aws Verified current stable Not installed? Cloud Infrastructure

Aws / Run Lambda Function

Run Lambda Function

Invoke a specified AWS Lambda function and save the response to a file.

$
Terminal
aws lambda invoke --function-name <name> <path/to/response.json>

When To Use

During testing phases of a Lambda function, when immediate output capture is required.

Pro Tip

Ensure that the file path for the response is correctly set to avoid file I/O errors; Lambda's execution role must have `AWSLambda_ReadOnlyAccess` policy if accessing resources.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
aws lambda invoke --function-name <name> <path/to/response.json>

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST",
    "Payload": "{\"result\":\"success\"}"
}

Anatomy of Output

Understanding the result

FunctionName: my-function Function Name

Identifies which Lambda function was invoked.

StatusCode: 200 HTTP Status Code

Indicates successful execution.

Payload: {"result": "Success"} Response Payload

JSON response returned by the Lambda function.

Power User Variants

Optimized versions

aws lambda invoke --function-name my-function --log-type Tail --query 'LogResult' --output text

Invoke the function while capturing log output.

Troubleshooting

Common pitfalls

An error occurred (ResourceNotFoundException) when calling the Invoke operation: Function not found: my-function

Solution: Verify the function name exists and is deployed in the correct region.

An error occurred (ServiceException) when calling the Invoke operation: Lambda function is throttled

Solution: Check concurrent execution limits, and adjust invocation frequency.

An error occurred (InvalidRequestContentException) when calling the Invoke operation: Invalid content type for payload

Solution: Ensure the payload is correctly formatted as JSON.

Command Breakdown

What each part is doing

aws
Base Command
The executable that performs this operation. Here it runs Aws before the shell applies any redirect operators.
<name>
name
The value supplied for name.
<path/to/response.json>
path to response.json
The value supplied for path to response.json.
--function-name
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Replace {{name}} with your function name and {{path/to/response.json}} with the response file path.

  2. Step 2

    Run the command: aws lambda invoke --function-name myFunction response.json.

  3. Step 3

    Check response.json to confirm function output and status.

Alternative Approaches

Comparable commands in other tools

Alternative cloud infrastructure tools for the same job.