aws lambda invoke: Call a Lambda from CI
aws lambda invoke runs a Lambda function synchronously or asynchronously and writes its response to a file, returning the status code and any FunctionError.
Smoke tests and post-deploy checks invoke the function directly. The classic trap is that a handler exception still returns HTTP 200; you must inspect the response body and FunctionError, not just the exit code.
What it does
aws lambda invoke executes --function-name, sending --payload as the event and writing the function output to the trailing outfile argument. The metadata response includes StatusCode and, if the handler threw, FunctionError set to "Unhandled" or "Handled".
Common usage
aws lambda invoke \
--function-name my-fn \
--payload '{"ping":true}' \
--cli-binary-format raw-in-base64-out \
--log-type Tail \
--query 'LogResult' --output text out.json | base64 -d
cat out.jsonOptions
| Flag | What it does |
|---|---|
| --function-name <name> | Function name, ARN, or partial ARN |
| --payload <json|file://> | Event passed to the handler |
| --cli-binary-format raw-in-base64-out | AWS CLI v2: treat --payload as raw JSON |
| --invocation-type RequestResponse|Event | Sync vs async (async returns 202) |
| --log-type Tail | Return last 4KB of logs in LogResult (base64) |
| --qualifier <version|alias> | Invoke a specific version or alias |
In CI
On AWS CLI v2 you must pass --cli-binary-format raw-in-base64-out, or --payload '{"k":1}' is interpreted as base64 and the handler receives garbage. A handler exception returns StatusCode 200 with FunctionError set, so gate on --query FunctionError being null, not on the CLI exit code alone.
Common errors in CI
"Invalid base64: ..." means you omitted --cli-binary-format raw-in-base64-out on CLI v2. "An error occurred (ResourceNotFoundException) when calling the Invoke operation: Function not found" means a wrong name/region/alias. "AccessDeniedException" means missing lambda:InvokeFunction. A 200 with "FunctionError":"Unhandled" in the output means the handler itself threw; read out.json for the stack trace.