AWS Lambda CLI
List Lambdas
aws lambda list-functions --max-items 10
or just list function names:
aws lambda list-functions --query 'Functions[].FunctionName'
Retrieve a Lambda
aws lambda get-function --function-name my-function
Create Lambda
aws lambda create-function --function-name my-function \
--zip-file fileb://function.zip \
--handler index.handler \
--runtime nodejs20.x \
--role arn:aws:iam::123456789012:role/lambda-ex
Update Lambda
aws lambda update-function-configuration --function-name my-function \
--memory-size 256
Delete Lambda
aws lambda delete-function --function-name my-function
Invoke Lambda and Get Logs
aws lambda invoke --function-name my-function out --log-type Tail
To decode these:
aws lambda invoke --function-name my-function out --log-type Tail \
--query 'LogResult' --output text | base64 -d
Example get-logs.sh
:
#!/bin/bash
aws lambda invoke --function-name my-function --cli-binary-format raw-in-base64-out --payload '{"key": "value"}' out
sed -i'' -e 's/"//g' out
sleep 15
aws logs get-log-events --log-group-name /aws/lambda/my-function --log-stream-name $(cat out) --limit 5