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.jsonCommon 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
aws lambda update-function-code: Deploy Lambda in CIaws lambda update-function-code deploys new Lambda code from a zip or ECR image. Learn the zip-file, image-ur…
aws logs tail: Stream CloudWatch Logs in CIaws logs tail streams or fetches CloudWatch Logs for a log group. Learn the follow, since, and filter-pattern…
aws sqs send-message: Send to an SQS Queue in CIaws sqs send-message enqueues a message to an SQS queue. Learn the queue-url, message-body, and FIFO group fl…