Notes to Self

Alex Sokolsky's Notes on Computers and Programming

AWS Lambda CLI

List Lambdas

list-functions

aws lambda list-functions --max-items 10

or just list function names:

aws lambda list-functions --query 'Functions[].FunctionName'

Retrieve a Lambda

get-function

aws lambda get-function --function-name my-function

Create Lambda

create-function

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

invoke

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