Lambda CLI

This guide explains how to use AWS Lambda over the CLI. The guide assumes you have already set up the AWS command line interface. You can verify proper setup using the command aws --version. Read the guide published by AWS for more information.


Create the execution role

aws iam create-role --role-name lambda-ex --assume-role-policy-document file://roles/trust-policy.json

Grant Lambda execution permissions to the role

aws iam attach-role-policy --role-name lambda-ex \
--policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

Delete a function

aws lambda delete-function --function-name my-function

Create deployment package

zip index.js

Create a function

aws lambda create-function --function-name my-function \
--zip-file fileb:// --handler index.handler --runtime nodejs12.x \
--role arn:aws:iam::123456789012:role/lambda-ex

Updating a function

aws lambda update-function-code --function-name my-function --zip-file fileb://

List Lambda functions

aws lambda list-functions --max-items 10

Invoke function with logs

aws lambda invoke --function-name my-function out --log-type Tail \
--query 'LogResult' --output text |  base64 -d