How to Invoke an AWS Lambda from the CLI

0 min read 146 words

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.

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags