How to Invoke an AWS Lambda From the CLI


If you want to invoke an AWS Lambda from your CLI, then the best option is to have the AWS CLI installed.

Getting started with the AWS CLI – AWS Command Line Interface (amazon.com)

Once this is installed, you can invoke Lambdas as follows:

Setting your AWS Region

It is recommended to always set your AWS region in an environment variable called AWS_REGION

export AWS_REGION=eu-west-1
aws lambda invoke --function-name YourFunction --region ${AWS_REGION} --cli-binary-format raw-in-base64-out --payload '{"keyName":"keyValue"}' response.json

Option 2 – If you need to use AWS CLI v1

aws lambda invoke --function-name YourFunction --region ${AWS_REGION} --payload $(echo '{"keyName":"keyValue"}') response.json

Logging

We specified a response.json at the end of the above commands. This is to get the output from the Lambda run.

You can also see detailed logs directly in the CloudWatch group associated to the above Lambda function.