AWS

AWS Lambda CLI

AWS Lambda CLI commands for serverless function management.

26 commands
Windows MacOS Linux
#serverless #cloud

Function Management

List all Lambda functions
aws lambda list-functions
Create a function
aws lambda create-function --function-name myFunc --runtime nodejs20.x --handler index.handler --role arn:aws:iam::123:role/role --zip-file fileb://code.zip
Update function code
aws lambda update-function-code --function-name myFunc --zip-file fileb://code.zip
Delete a function
aws lambda delete-function --function-name myFunc
Get function details
aws lambda get-function --function-name myFunc
Publish a new version
aws lambda publish-version --function-name myFunc

Invocation

Invoke function synchronously
aws lambda invoke --function-name myFunc output.json
Invoke asynchronously
aws lambda invoke --function-name myFunc --invocation-type Event out.json
Invoke with JSON payload
aws lambda invoke --function-name myFunc --payload '{"key":"val"}' out.json
Invoke and return logs
aws lambda invoke --function-name myFunc --log-type Tail out.json

Layers

List all Lambda layers
aws lambda list-layers
Publish a layer
aws lambda publish-layer-version --layer-name myLayer --zip-file fileb://layer.zip --compatible-runtimes nodejs20.x
List versions of a layer
aws lambda list-layer-versions --layer-name myLayer
Delete layer version
aws lambda delete-layer-version --layer-name myLayer --version-number 1

Event Sources

List event source mappings
aws lambda list-event-source-mappings --function-name myFunc
Map SQS to function
aws lambda create-event-source-mapping --function-name myFunc --event-source-arn arn:aws:sqs:us-east-1:123:myQueue --batch-size 10
Delete event source mapping
aws lambda delete-event-source-mapping --uuid abc-123-def
Update mapping config
aws lambda update-event-source-mapping --uuid abc-123 --batch-size 20

Configuration

Update timeout and memory
aws lambda update-function-configuration --function-name myFunc --timeout 30 --memory-size 512
Set reserved concurrency
aws lambda put-function-concurrency --function-name myFunc --reserved-concurrent-executions 100
Get function configuration
aws lambda get-function-configuration --function-name myFunc
Set environment variables
aws lambda update-function-configuration --function-name myFunc --environment "Variables={KEY=value}"
Create function alias
aws lambda create-alias --function-name myFunc --name prod --function-version 1

Quick Commands

List all Lambda functions in the account
aws lambda list-functions
Invoke a Lambda function and save response
aws lambda invoke --function-name <name> output.json
Deploy new code to a Lambda function
aws lambda update-function-code --function-name <name> --zip-file fileb://code.zip