Skip to content
Latchkey

aws lambda invoke: Invoke a Lambda Function in CI

Trigger a Lambda function and write its response payload to a file.

aws lambda invoke calls a function synchronously (or async) and writes the response to an output file. In CI it is used as a post-deploy smoke test - invoke the function with a known payload and assert on the result.

Common flags

  • --function-name - the function to call (required)
  • --payload - the request payload (JSON; needs --cli-binary-format on v2)
  • --cli-binary-format raw-in-base64-out - pass raw JSON payload in CLI v2
  • --log-type Tail - return base64-encoded last 4KB of logs
  • --invocation-type Event - invoke asynchronously

Example in CI

Smoke test a function after deploy.

shell
aws lambda invoke --function-name my-api --cli-binary-format raw-in-base64-out --payload '{"ping":true}' response.json

Common errors in CI

  • Invalid base64 - CLI v2 needs --cli-binary-format raw-in-base64-out for raw JSON
  • An error occurred (ResourceNotFoundException) - function name/region wrong
  • FunctionError in the response - the function threw; check response.json and tailed logs
  • An error occurred (AccessDeniedException) - role lacks lambda:InvokeFunction

Key takeaways

  • CLI v2 requires --cli-binary-format raw-in-base64-out to pass raw JSON payloads.
  • A 200 status with FunctionError still means the handler threw - inspect the output file.
  • Use --log-type Tail to capture the last 4KB of execution logs in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →