serverless/serverless · error · ServerlessError

FILE_NOT_FOUND

FILE_NOT_FOUND

Error message

The file you provided does not exist.

What it means

Thrown by the invoke-agent plugin when the --path file (agent input payload) cannot be read because it does not exist: serverless.utils.readFile rejects with ENOENT. The path is resolved relative to the service directory.

Source

Thrown at packages/serverless/lib/plugins/aws/invoke-agent.js:119

      } catch {
        // Keep as string if not valid JSON
      }
    }
  }

  /**
   * Validate file exists and return contents
   */
  async validateFile(key) {
    const absolutePath = path.resolve(
      this.serverless.serviceDir,
      this.options[key],
    )
    try {
      return await this.serverless.utils.readFile(absolutePath)
    } catch (err) {
      if (err.code === 'ENOENT') {
        throw new ServerlessError(
          'The file you provided does not exist.',
          'FILE_NOT_FOUND',
        )
      }
      throw err
    }
  }

  /**
   * Get ai configuration
   */
  getAiConfig() {
    const service = this.serverless.service

    if (service.ai) {
      return service.ai
    }

View on GitHub (pinned to b9d7ea51c8)

Solutions

  1. Confirm the path is relative to the service root (where serverless.yml lives).
  2. Use an absolute path to remove ambiguity.
  3. Create the file if it is genuinely missing.

Example fix

# before
sls invoke --agent myAgent --path ./dta/input.json
# after
sls invoke --agent myAgent --path ./data/input.json
Defensive patterns

Strategy: validation

Validate before calling

import { pathExists } from 'fs-extra'
import path from 'path'
async function ensureInputFile(serviceDir, rel) {
  const abs = path.resolve(serviceDir, rel)
  if (!(await pathExists(abs))) throw new Error(`--path file not found: ${abs}`)
  return abs
}

Prevention

When it happens

Trigger: Running `sls invoke --agent X --path missing.json` where the file is absent.

Common situations: Wrong relative path; file located outside the service dir; typo in the filename; file deleted between commands.

Related errors


AI-assisted analysis of serverless/serverless@b9d7ea51c8 (2026-08-13). Data as JSON: /api/errors/550f04329d321f77. Report an issue: GitHub.