This documentation is for Version 1 of the Amazon CLI only. For documentation related to Version 2 of the Amazon CLI, see the Version 2 User Guide.
Lambda examples using Amazon CLI
The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with Lambda.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use add-layer-version-permission
.
- Amazon CLI
-
To add permissions to a layer version
The following
add-layer-version-permission
example grants permission for the specified account to use version 1 of the layermy-layer
.aws lambda add-layer-version-permission \ --layer-name
my-layer
\ --statement-idxaccount
\ --actionlambda:GetLayerVersion
\ --principal123456789012
\ --version-number1
Output:
{ "RevisionId": "35d87451-f796-4a3f-a618-95a3671b0a0c", "Statement": { "Sid":"xaccount", "Effect":"Allow", "Principal":{ "AWS":"arn:aws:iam::210987654321:root" }, "Action":"lambda:GetLayerVersion", "Resource":"arn:aws:lambda:us-east-2:123456789012:layer:my-layer:1" } }
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see AddLayerVersionPermission
in Amazon CLI Command Reference.
-
The following code example shows how to use add-permission
.
- Amazon CLI
-
To add permissions to an existing Lambda function
The following
add-permission
example grants the Amazon SNS service permission to invoke a function namedmy-function
.aws lambda add-permission \ --function-name
my-function
\ --actionlambda:InvokeFunction
\ --statement-idsns
\ --principalsns.amazonaws.com
Output:
{ "Statement": { "Sid":"sns", "Effect":"Allow", "Principal":{ "Service":"sns.amazonaws.com" }, "Action":"lambda:InvokeFunction", "Resource":"arn:aws:lambda:us-east-2:123456789012:function:my-function" } }
For more information, see Using Resource-based Policies for Amazon Lambda
in the Amazon Lambda Developer Guide. -
For API details, see AddPermission
in Amazon CLI Command Reference.
-
The following code example shows how to use create-alias
.
- Amazon CLI
-
To create an alias for a Lambda function
The following
create-alias
example creates an alias namedLIVE
that points to version 1 of themy-function
Lambda function.aws lambda create-alias \ --function-name
my-function
\ --description"alias for live version of function"
\ --function-version1
\ --nameLIVE
Output:
{ "FunctionVersion": "1", "Name": "LIVE", "AliasArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:LIVE", "RevisionId": "873282ed-4cd3-4dc8-a069-d0c647e470c6", "Description": "alias for live version of function" }
For more information, see Configuring Amazon Lambda Function Aliases
in the Amazon Lambda Developer Guide. -
For API details, see CreateAlias
in Amazon CLI Command Reference.
-
The following code example shows how to use create-event-source-mapping
.
- Amazon CLI
-
To create a mapping between an event source and an Amazon Lambda function
The following
create-event-source-mapping
example creates a mapping between an SQS queue and themy-function
Lambda function.aws lambda create-event-source-mapping \ --function-name
my-function
\ --batch-size5
\ --event-source-arnarn:aws:sqs:us-west-2:123456789012:mySQSqueue
Output:
{ "UUID": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "StateTransitionReason": "USER_INITIATED", "LastModified": 1569284520.333, "BatchSize": 5, "State": "Creating", "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "EventSourceArn": "arn:aws:sqs:us-west-2:123456789012:mySQSqueue" }
For more information, see Amazon Lambda Event Source Mapping
in the Amazon Lambda Developer Guide. -
For API details, see CreateEventSourceMapping
in Amazon CLI Command Reference.
-
The following code example shows how to use create-function
.
- Amazon CLI
-
To create a Lambda function
The following
create-function
example creates a Lambda function namedmy-function
.aws lambda create-function \ --function-name
my-function
\ --runtimenodejs18.x
\ --zip-filefileb://my-function.zip
\ --handlermy-function.handler
\ --rolearn:aws:iam::123456789012:role/service-role/MyTestFunction-role-tges6bf4
Contents of
my-function.zip
:This file is a deployment package that contains your function code and any dependencies.
Output:
{ "TracingConfig": { "Mode": "PassThrough" }, "CodeSha256": "PFn4S+er27qk+UuZSTKEQfNKG/XNn7QJs90mJgq6oH8=", "FunctionName": "my-function", "CodeSize": 308, "RevisionId": "873282ed-4cd3-4dc8-a069-d0c647e470c6", "MemorySize": 128, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "Version": "$LATEST", "Role": "arn:aws:iam::123456789012:role/service-role/MyTestFunction-role-zgur6bf4", "Timeout": 3, "LastModified": "2023-10-14T22:26:11.234+0000", "Handler": "my-function.handler", "Runtime": "nodejs18.x", "Description": "" }
For more information, see Amazon Lambda Function Configuration
in the Amazon Lambda Developer Guide. -
For API details, see CreateFunction
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-alias
.
- Amazon CLI
-
To delete an alias of a Lambda function
The following
delete-alias
example deletes the alias namedLIVE
from themy-function
Lambda function.aws lambda delete-alias \ --function-name
my-function
\ --nameLIVE
This command produces no output.
For more information, see Configuring Amazon Lambda Function Aliases
in the Amazon Lambda Developer Guide. -
For API details, see DeleteAlias
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-event-source-mapping
.
- Amazon CLI
-
To delete the mapping between an event source and an Amazon Lambda function
The following
delete-event-source-mapping
example deletes the mapping between an SQS queue and themy-function
Lambda function.aws lambda delete-event-source-mapping \ --uuid
a1b2c3d4-5678-90ab-cdef-11111EXAMPLE
Output:
{ "UUID": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "StateTransitionReason": "USER_INITIATED", "LastModified": 1569285870.271, "BatchSize": 5, "State": "Deleting", "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "EventSourceArn": "arn:aws:sqs:us-west-2:123456789012:mySQSqueue" }
For more information, see Amazon Lambda Event Source Mapping
in the Amazon Lambda Developer Guide. -
For API details, see DeleteEventSourceMapping
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-function-concurrency
.
- Amazon CLI
-
To remove the reserved concurrent execution limit from a function
The following
delete-function-concurrency
example deletes the reserved concurrent execution limit from themy-function
function.aws lambda delete-function-concurrency \ --function-name
my-function
This command produces no output.
For more information, see Reserving Concurrency for a Lambda Function
in the Amazon Lambda Developer Guide. -
For API details, see DeleteFunctionConcurrency
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-function-event-invoke-config
.
- Amazon CLI
-
To delete an asynchronous invocation configuration
The following
delete-function-event-invoke-config
example deletes the asynchronous invocation configuration for theGREEN
alias of the specified function.aws lambda delete-function-event-invoke-config --function-name
my-function:GREEN
-
For API details, see DeleteFunctionEventInvokeConfig
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-function
.
- Amazon CLI
-
Example 1: To delete a Lambda function by function name
The following
delete-function
example deletes the Lambda function namedmy-function
by specifying the function's name.aws lambda delete-function \ --function-name
my-function
This command produces no output.
Example 2: To delete a Lambda function by function ARN
The following
delete-function
example deletes the Lambda function namedmy-function
by specifying the function's ARN.aws lambda delete-function \ --function-name
arn:aws:lambda:us-west-2:123456789012:function:my-function
This command produces no output.
Example 3: To delete a Lambda function by partial function ARN
The following
delete-function
example deletes the Lambda function namedmy-function
by specifying the function's partial ARN.aws lambda delete-function \ --function-name
123456789012:function:my-function
This command produces no output.
For more information, see Amazon Lambda Function Configuration
in the Amazon Lambda Developer Guide. -
For API details, see DeleteFunction
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-layer-version
.
- Amazon CLI
-
To delete a version of a Lambda layer
The following
delete-layer-version
example deletes version 2 of the layer namedmy-layer
.aws lambda delete-layer-version \ --layer-name
my-layer
\ --version-number2
This command produces no output.
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see DeleteLayerVersion
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-provisioned-concurrency-config
.
- Amazon CLI
-
To delete a provisioned concurrency configuration
The following
delete-provisioned-concurrency-config
example deletes the provisioned concurrency configuration for theGREEN
alias of the specified function.aws lambda delete-provisioned-concurrency-config \ --function-name
my-function
\ --qualifierGREEN
-
For API details, see DeleteProvisionedConcurrencyConfig
in Amazon CLI Command Reference.
-
The following code example shows how to use get-account-settings
.
- Amazon CLI
-
To retrieve details about your account in an Amazon Region
The following
get-account-settings
example displays the Lambda limits and usage information for your account.aws lambda get-account-settings
Output:
{ "AccountLimit": { "CodeSizeUnzipped": 262144000, "UnreservedConcurrentExecutions": 1000, "ConcurrentExecutions": 1000, "CodeSizeZipped": 52428800, "TotalCodeSize": 80530636800 }, "AccountUsage": { "FunctionCount": 4, "TotalCodeSize": 9426 } }
For more information, see Amazon Lambda Limits
in the Amazon Lambda Developer Guide. -
For API details, see GetAccountSettings
in Amazon CLI Command Reference.
-
The following code example shows how to use get-alias
.
- Amazon CLI
-
To retrieve details about a function alias
The following
get-alias
example displays details for the alias namedLIVE
on themy-function
Lambda function.aws lambda get-alias \ --function-name
my-function
\ --nameLIVE
Output:
{ "FunctionVersion": "3", "Name": "LIVE", "AliasArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:LIVE", "RevisionId": "594f41fb-b85f-4c20-95c7-6ca5f2a92c93", "Description": "alias for live version of function" }
For more information, see Configuring Amazon Lambda Function Aliases
in the Amazon Lambda Developer Guide. -
For API details, see GetAlias
in Amazon CLI Command Reference.
-
The following code example shows how to use get-event-source-mapping
.
- Amazon CLI
-
To retrieve details about an event source mapping
The following
get-event-source-mapping
example displays the details for the mapping between an SQS queue and themy-function
Lambda function.aws lambda get-event-source-mapping \ --uuid
"a1b2c3d4-5678-90ab-cdef-11111EXAMPLE"
Output:
{ "UUID": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "StateTransitionReason": "USER_INITIATED", "LastModified": 1569284520.333, "BatchSize": 5, "State": "Enabled", "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "EventSourceArn": "arn:aws:sqs:us-west-2:123456789012:mySQSqueue" }
For more information, see Amazon Lambda Event Source Mapping
in the Amazon Lambda Developer Guide. -
For API details, see GetEventSourceMapping
in Amazon CLI Command Reference.
-
The following code example shows how to use get-function-concurrency
.
- Amazon CLI
-
To view the reserved concurrency setting for a function
The following
get-function-concurrency
example retrieves the reserved concurrency setting for the specified function.aws lambda get-function-concurrency \ --function-name
my-function
Output:
{ "ReservedConcurrentExecutions": 250 }
-
For API details, see GetFunctionConcurrency
in Amazon CLI Command Reference.
-
The following code example shows how to use get-function-configuration
.
- Amazon CLI
-
To retrieve the version-specific settings of a Lambda function
The following
get-function-configuration
example displays the settings for version 2 of themy-function
function.aws lambda get-function-configuration \ --function-name
my-function:2
Output:
{ "FunctionName": "my-function", "LastModified": "2019-09-26T20:28:40.438+0000", "RevisionId": "e52502d4-9320-4688-9cd6-152a6ab7490d", "MemorySize": 256, "Version": "2", "Role": "arn:aws:iam::123456789012:role/service-role/my-function-role-uy3l9qyq", "Timeout": 3, "Runtime": "nodejs10.x", "TracingConfig": { "Mode": "PassThrough" }, "CodeSha256": "5tT2qgzYUHaqwR716pZ2dpkn/0J1FrzJmlKidWoaCgk=", "Description": "", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "CodeSize": 304, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:2", "Handler": "index.handler" }
For more information, see Amazon Lambda Function Configuration
in the Amazon Lambda Developer Guide. -
For API details, see GetFunctionConfiguration
in Amazon CLI Command Reference.
-
The following code example shows how to use get-function-event-invoke-config
.
- Amazon CLI
-
To view an asynchronous invocation configuration
The following
get-function-event-invoke-config
example retrieves the asynchronous invocation configuration for theBLUE
alias of the specified function.aws lambda get-function-event-invoke-config \ --function-name
my-function:BLUE
Output:
{ "LastModified": 1577824396.653, "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function:BLUE", "MaximumRetryAttempts": 0, "MaximumEventAgeInSeconds": 3600, "DestinationConfig": { "OnSuccess": {}, "OnFailure": { "Destination": "arn:aws:sqs:us-east-2:123456789012:failed-invocations" } } }
-
For API details, see GetFunctionEventInvokeConfig
in Amazon CLI Command Reference.
-
The following code example shows how to use get-function
.
- Amazon CLI
-
To retrieve information about a function
The following
get-function
example displays information about themy-function
function.aws lambda get-function \ --function-name
my-function
Output:
{ "Concurrency": { "ReservedConcurrentExecutions": 100 }, "Code": { "RepositoryType": "S3", "Location": "https://awslambda-us-west-2-tasks.s3.us-west-2.amazonaws.com/snapshots/123456789012/my-function..." }, "Configuration": { "TracingConfig": { "Mode": "PassThrough" }, "Version": "$LATEST", "CodeSha256": "5tT2qgzYUHoqwR616pZ2dpkn/0J1FrzJmlKidWaaCgk=", "FunctionName": "my-function", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "MemorySize": 128, "RevisionId": "28f0fb31-5c5c-43d3-8955-03e76c5c1075", "CodeSize": 304, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "Handler": "index.handler", "Role": "arn:aws:iam::123456789012:role/service-role/helloWorldPython-role-uy3l9qyq", "Timeout": 3, "LastModified": "2019-09-24T18:20:35.054+0000", "Runtime": "nodejs10.x", "Description": "" } }
For more information, see Amazon Lambda Function Configuration
in the Amazon Lambda Developer Guide. -
For API details, see GetFunction
in Amazon CLI Command Reference.
-
The following code example shows how to use get-layer-version-by-arn
.
- Amazon CLI
-
To retrieve information about a Lambda layer version
The following
get-layer-version-by-arn
example displays information about the layer version with the specified Amazon Resource Name (ARN).aws lambda get-layer-version-by-arn \ --arn
"arn:aws:lambda:us-west-2:123456789012:layer:AWSLambda-Python311-SciPy1x:2"
Output:
{ "LayerVersionArn": "arn:aws:lambda:us-west-2:123456789012:layer:AWSLambda-Python311-SciPy1x:2", "Description": "AWS Lambda SciPy layer for Python 3.11 (scipy-1.1.0, numpy-1.15.4) https://github.com/scipy/scipy/releases/tag/v1.1.0 https://github.com/numpy/numpy/releases/tag/v1.15.4", "CreatedDate": "2023-10-12T10:09:38.398+0000", "LayerArn": "arn:aws:lambda:us-west-2:123456789012:layer:AWSLambda-Python311-SciPy1x", "Content": { "CodeSize": 41784542, "CodeSha256": "GGmv8ocUw4cly0T8HL0Vx/f5V4RmSCGNjDIslY4VskM=", "Location": "https://awslambda-us-west-2-layers.s3.us-west-2.amazonaws.com/snapshots/123456789012/..." }, "Version": 2, "CompatibleRuntimes": [ "python3.11" ], "LicenseInfo": "SciPy: https://github.com/scipy/scipy/blob/main/LICENSE.txt, NumPy: https://github.com/numpy/numpy/blob/main/LICENSE.txt" }
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see GetLayerVersionByArn
in Amazon CLI Command Reference.
-
The following code example shows how to use get-layer-version-policy
.
- Amazon CLI
-
To retrieve the permissions policy for a Lambda layer version
The following
get-layer-version-policy
example displays policy information about version 1 for the layer namedmy-layer
.aws lambda get-layer-version-policy \ --layer-name
my-layer
\ --version-number1
Output:
{ "Policy": { "Version":"2012-10-17", "Id":"default", "Statement": [ { "Sid":"xaccount", "Effect":"Allow", "Principal": {"AWS":"arn:aws:iam::123456789012:root"}, "Action":"lambda:GetLayerVersion", "Resource":"arn:aws:lambda:us-west-2:123456789012:layer:my-layer:1" } ] }, "RevisionId": "c68f21d2-cbf0-4026-90f6-1375ee465cd0" }
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see GetLayerVersionPolicy
in Amazon CLI Command Reference.
-
The following code example shows how to use get-layer-version
.
- Amazon CLI
-
To retrieve information about a Lambda layer version
The following
get-layer-version
example displays information for version 1 of the layer namedmy-layer
.aws lambda get-layer-version \ --layer-name
my-layer
\ --version-number1
Output:
{ "Content": { "Location": "https://awslambda-us-east-2-layers.s3.us-east-2.amazonaws.com/snapshots/123456789012/my-layer-4aaa2fbb-ff77-4b0a-ad92-5b78a716a96a?versionId=27iWyA73cCAYqyH...", "CodeSha256": "tv9jJO+rPbXUUXuRKi7CwHzKtLDkDRJLB3cC3Z/ouXo=", "CodeSize": 169 }, "LayerArn": "arn:aws:lambda:us-east-2:123456789012:layer:my-layer", "LayerVersionArn": "arn:aws:lambda:us-east-2:123456789012:layer:my-layer:1", "Description": "My Python layer", "CreatedDate": "2018-11-14T23:03:52.894+0000", "Version": 1, "LicenseInfo": "MIT", "CompatibleRuntimes": [ "python3.10", "python3.11" ] }
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see GetLayerVersion
in Amazon CLI Command Reference.
-
The following code example shows how to use get-policy
.
- Amazon CLI
-
To retrieve the resource-based IAM policy for a function, version, or alias
The following
get-policy
example displays policy information about themy-function
Lambda function.aws lambda get-policy \ --function-name
my-function
Output:
{ "Policy": { "Version":"2012-10-17", "Id":"default", "Statement": [ { "Sid":"iot-events", "Effect":"Allow", "Principal": {"Service":"iotevents.amazonaws.com"}, "Action":"lambda:InvokeFunction", "Resource":"arn:aws:lambda:us-west-2:123456789012:function:my-function" } ] }, "RevisionId": "93017fc9-59cb-41dc-901b-4845ce4bf668" }
For more information, see Using Resource-based Policies for Amazon Lambda
in the Amazon Lambda Developer Guide. -
For API details, see GetPolicy
in Amazon CLI Command Reference.
-
The following code example shows how to use get-provisioned-concurrency-config
.
- Amazon CLI
-
To view a provisioned concurrency configuration
The following
get-provisioned-concurrency-config
example displays details for the provisioned concurrency configuration for theBLUE
alias of the specified function.aws lambda get-provisioned-concurrency-config \ --function-name
my-function
\ --qualifierBLUE
Output:
{ "RequestedProvisionedConcurrentExecutions": 100, "AvailableProvisionedConcurrentExecutions": 100, "AllocatedProvisionedConcurrentExecutions": 100, "Status": "READY", "LastModified": "2019-12-31T20:28:49+0000" }
-
For API details, see GetProvisionedConcurrencyConfig
in Amazon CLI Command Reference.
-
The following code example shows how to use invoke
.
- Amazon CLI
-
Example 1: To invoke a Lambda function synchronously
The following
invoke
example invokes themy-function
function synchronously. Thecli-binary-format
option is required if you're using Amazon CLI version 2. For more information, see Amazon CLI supported global command line optionsin the Amazon Command Line Interface User Guide. aws lambda invoke \ --function-name
my-function
\ --cli-binary-formatraw-in-base64-out
\ --payload '{ "name": "Bob" }
' \response.json
Output:
{ "ExecutedVersion": "$LATEST", "StatusCode": 200 }
For more information, see Synchronous Invocation
in the Amazon Lambda Developer Guide. Example 2: To invoke a Lambda function asynchronously
The following
invoke
example invokes themy-function
function asynchronously. Thecli-binary-format
option is required if you're using Amazon CLI version 2. For more information, see Amazon CLI supported global command line optionsin the Amazon Command Line Interface User Guide. aws lambda invoke \ --function-name
my-function
\ --invocation-typeEvent
\ --cli-binary-formatraw-in-base64-out
\ --payload '{ "name": "Bob" }
' \response.json
Output:
{ "StatusCode": 202 }
For more information, see Asynchronous Invocation
in the Amazon Lambda Developer Guide. -
For API details, see Invoke
in Amazon CLI Command Reference.
-
The following code example shows how to use list-aliases
.
- Amazon CLI
-
To retrieve the list of aliases for a Lambda function
The following
list-aliases
example displays a list of the aliases for themy-function
Lambda function.aws lambda list-aliases \ --function-name
my-function
Output:
{ "Aliases": [ { "AliasArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:BETA", "RevisionId": "a410117f-ab16-494e-8035-7e204bb7933b", "FunctionVersion": "2", "Name": "BETA", "Description": "alias for beta version of function" }, { "AliasArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:LIVE", "RevisionId": "21d40116-f8b1-40ba-9360-3ea284da1bb5", "FunctionVersion": "1", "Name": "LIVE", "Description": "alias for live version of function" } ] }
For more information, see Configuring Amazon Lambda Function Aliases
in the Amazon Lambda Developer Guide. -
For API details, see ListAliases
in Amazon CLI Command Reference.
-
The following code example shows how to use list-event-source-mappings
.
- Amazon CLI
-
To list the event source mappings for a function
The following
list-event-source-mappings
example displays a list of the event source mappings for themy-function
Lambda function.aws lambda list-event-source-mappings \ --function-name
my-function
Output:
{ "EventSourceMappings": [ { "UUID": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "StateTransitionReason": "USER_INITIATED", "LastModified": 1569284520.333, "BatchSize": 5, "State": "Enabled", "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "EventSourceArn": "arn:aws:sqs:us-west-2:123456789012:mySQSqueue" } ] }
For more information, see Amazon Lambda Event Source Mapping
in the Amazon Lambda Developer Guide. -
For API details, see ListEventSourceMappings
in Amazon CLI Command Reference.
-
The following code example shows how to use list-function-event-invoke-configs
.
- Amazon CLI
-
To view a list of asynchronous invocation configurations
The following
list-function-event-invoke-configs
example lists the asynchronous invocation configurations for the specified function.aws lambda list-function-event-invoke-configs \ --function-name
my-function
Output:
{ "FunctionEventInvokeConfigs": [ { "LastModified": 1577824406.719, "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function:GREEN", "MaximumRetryAttempts": 2, "MaximumEventAgeInSeconds": 1800 }, { "LastModified": 1577824396.653, "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function:BLUE", "MaximumRetryAttempts": 0, "MaximumEventAgeInSeconds": 3600 } ] }
-
For API details, see ListFunctionEventInvokeConfigs
in Amazon CLI Command Reference.
-
The following code example shows how to use list-functions
.
- Amazon CLI
-
To retrieve a list of Lambda functions
The following
list-functions
example displays a list of all of the functions for the current user.aws lambda list-functions
Output:
{ "Functions": [ { "TracingConfig": { "Mode": "PassThrough" }, "Version": "$LATEST", "CodeSha256": "dBG9m8SGdmlEjw/JYXlhhvCrAv5TxvXsbL/RMr0fT/I=", "FunctionName": "helloworld", "MemorySize": 128, "RevisionId": "1718e831-badf-4253-9518-d0644210af7b", "CodeSize": 294, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:helloworld", "Handler": "helloworld.handler", "Role": "arn:aws:iam::123456789012:role/service-role/MyTestFunction-role-zgur6bf4", "Timeout": 3, "LastModified": "2023-09-23T18:32:33.857+0000", "Runtime": "nodejs18.x", "Description": "" }, { "TracingConfig": { "Mode": "PassThrough" }, "Version": "$LATEST", "CodeSha256": "sU0cJ2/hOZevwV/lTxCuQqK3gDZP3i8gUoqUUVRmY6E=", "FunctionName": "my-function", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "MemorySize": 256, "RevisionId": "93017fc9-59cb-41dc-901b-4845ce4bf668", "CodeSize": 266, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "Handler": "index.handler", "Role": "arn:aws:iam::123456789012:role/service-role/helloWorldPython-role-uy3l9qyq", "Timeout": 3, "LastModified": "2023-10-01T16:47:28.490+0000", "Runtime": "nodejs18.x", "Description": "" }, { "Layers": [ { "CodeSize": 41784542, "Arn": "arn:aws:lambda:us-west-2:420165488524:layer:AWSLambda-Python37-SciPy1x:2" }, { "CodeSize": 4121, "Arn": "arn:aws:lambda:us-west-2:123456789012:layer:pythonLayer:1" } ], "TracingConfig": { "Mode": "PassThrough" }, "Version": "$LATEST", "CodeSha256": "ZQukCqxtkqFgyF2cU41Avj99TKQ/hNihPtDtRcc08mI=", "FunctionName": "my-python-function", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "MemorySize": 128, "RevisionId": "80b4eabc-acf7-4ea8-919a-e874c213707d", "CodeSize": 299, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-python-function", "Handler": "lambda_function.lambda_handler", "Role": "arn:aws:iam::123456789012:role/service-role/my-python-function-role-z5g7dr6n", "Timeout": 3, "LastModified": "2023-10-01T19:40:41.643+0000", "Runtime": "python3.11", "Description": "" } ] }
For more information, see Amazon Lambda Function Configuration
in the Amazon Lambda Developer Guide. -
For API details, see ListFunctions
in Amazon CLI Command Reference.
-
The following code example shows how to use list-layer-versions
.
- Amazon CLI
-
To list the versions of an Amazon Lambda layer
The following
list-layers-versions
example displays information about the versions for the layer namedmy-layer
.aws lambda list-layer-versions \ --layer-name
my-layer
Output:
{ "Layers": [ { "LayerVersionArn": "arn:aws:lambda:us-east-2:123456789012:layer:my-layer:2", "Version": 2, "Description": "My layer", "CreatedDate": "2023-11-15T00:37:46.592+0000", "CompatibleRuntimes": [ "python3.10", "python3.11" ] } ] }
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see ListLayerVersions
in Amazon CLI Command Reference.
-
The following code example shows how to use list-layers
.
- Amazon CLI
-
To list the layers that are compatible with your function's runtime
The following
list-layers
example displays information about layers that are compatible with the Python 3.11 runtime.aws lambda list-layers \ --compatible-runtime
python3.11
Output:
{ "Layers": [ { "LayerName": "my-layer", "LayerArn": "arn:aws:lambda:us-east-2:123456789012:layer:my-layer", "LatestMatchingVersion": { "LayerVersionArn": "arn:aws:lambda:us-east-2:123456789012:layer:my-layer:2", "Version": 2, "Description": "My layer", "CreatedDate": "2023-11-15T00:37:46.592+0000", "CompatibleRuntimes": [ "python3.10", "python3.11" ] } } ] }
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see ListLayers
in Amazon CLI Command Reference.
-
The following code example shows how to use list-provisioned-concurrency-configs
.
- Amazon CLI
-
To get a list of provisioned concurrency configurations
The following
list-provisioned-concurrency-configs
example lists the provisioned concurrency configurations for the specified function.aws lambda list-provisioned-concurrency-configs \ --function-name
my-function
Output:
{ "ProvisionedConcurrencyConfigs": [ { "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function:GREEN", "RequestedProvisionedConcurrentExecutions": 100, "AvailableProvisionedConcurrentExecutions": 100, "AllocatedProvisionedConcurrentExecutions": 100, "Status": "READY", "LastModified": "2019-12-31T20:29:00+0000" }, { "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function:BLUE", "RequestedProvisionedConcurrentExecutions": 100, "AvailableProvisionedConcurrentExecutions": 100, "AllocatedProvisionedConcurrentExecutions": 100, "Status": "READY", "LastModified": "2019-12-31T20:28:49+0000" } ] }
-
For API details, see ListProvisionedConcurrencyConfigs
in Amazon CLI Command Reference.
-
The following code example shows how to use list-tags
.
- Amazon CLI
-
To retrieve the list of tags for a Lambda function
The following
list-tags
example displays the tags attached to themy-function
Lambda function.aws lambda list-tags \ --resource
arn:aws:lambda:us-west-2:123456789012:function:my-function
Output:
{ "Tags": { "Category": "Web Tools", "Department": "Sales" } }
For more information, see Tagging Lambda Functions
in the Amazon Lambda Developer Guide. -
For API details, see ListTags
in Amazon CLI Command Reference.
-
The following code example shows how to use list-versions-by-function
.
- Amazon CLI
-
To retrieve a list of versions of a function
The following
list-versions-by-function
example displays the list of versions for themy-function
Lambda function.aws lambda list-versions-by-function \ --function-name
my-function
Output:
{ "Versions": [ { "TracingConfig": { "Mode": "PassThrough" }, "Version": "$LATEST", "CodeSha256": "sU0cJ2/hOZevwV/lTxCuQqK3gDZP3i8gUoqUUVRmY6E=", "FunctionName": "my-function", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "MemorySize": 256, "RevisionId": "93017fc9-59cb-41dc-901b-4845ce4bf668", "CodeSize": 266, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:$LATEST", "Handler": "index.handler", "Role": "arn:aws:iam::123456789012:role/service-role/helloWorldPython-role-uy3l9qyq", "Timeout": 3, "LastModified": "2019-10-01T16:47:28.490+0000", "Runtime": "nodejs10.x", "Description": "" }, { "TracingConfig": { "Mode": "PassThrough" }, "Version": "1", "CodeSha256": "5tT2qgzYUHoqwR616pZ2dpkn/0J1FrzJmlKidWaaCgk=", "FunctionName": "my-function", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "MemorySize": 256, "RevisionId": "949c8914-012e-4795-998c-e467121951b1", "CodeSize": 304, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:1", "Handler": "index.handler", "Role": "arn:aws:iam::123456789012:role/service-role/helloWorldPython-role-uy3l9qyq", "Timeout": 3, "LastModified": "2019-09-26T20:28:40.438+0000", "Runtime": "nodejs10.x", "Description": "new version" }, { "TracingConfig": { "Mode": "PassThrough" }, "Version": "2", "CodeSha256": "sU0cJ2/hOZevwV/lTxCuQqK3gDZP3i8gUoqUUVRmY6E=", "FunctionName": "my-function", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "MemorySize": 256, "RevisionId": "cd669f21-0f3d-4e1c-9566-948837f2e2ea", "CodeSize": 266, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:2", "Handler": "index.handler", "Role": "arn:aws:iam::123456789012:role/service-role/helloWorldPython-role-uy3l9qyq", "Timeout": 3, "LastModified": "2019-10-01T16:47:28.490+0000", "Runtime": "nodejs10.x", "Description": "newer version" } ] }
For more information, see Configuring Amazon Lambda Function Aliases
in the Amazon Lambda Developer Guide. -
For API details, see ListVersionsByFunction
in Amazon CLI Command Reference.
-
The following code example shows how to use publish-layer-version
.
- Amazon CLI
-
To create a Lambda layer version
The following
publish-layer-version
example creates a new Python library layer version. The command retrieves the layer content a file namedlayer.zip
in the specified S3 bucket.aws lambda publish-layer-version \ --layer-name
my-layer
\ --description"My Python layer"
\ --license-info"MIT"
\ --contentS3Bucket=lambda-layers-us-west-2-123456789012,S3Key=layer.zip
\ --compatible-runtimespython3.10
python3.11
Output:
{ "Content": { "Location": "https://awslambda-us-west-2-layers.s3.us-west-2.amazonaws.com/snapshots/123456789012/my-layer-4aaa2fbb-ff77-4b0a-ad92-5b78a716a96a?versionId=27iWyA73cCAYqyH...", "CodeSha256": "tv9jJO+rPbXUUXuRKi7CwHzKtLDkDRJLB3cC3Z/ouXo=", "CodeSize": 169 }, "LayerArn": "arn:aws:lambda:us-west-2:123456789012:layer:my-layer", "LayerVersionArn": "arn:aws:lambda:us-west-2:123456789012:layer:my-layer:1", "Description": "My Python layer", "CreatedDate": "2023-11-14T23:03:52.894+0000", "Version": 1, "LicenseInfo": "MIT", "CompatibleRuntimes": [ "python3.10", "python3.11" ] }
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see PublishLayerVersion
in Amazon CLI Command Reference.
-
The following code example shows how to use publish-version
.
- Amazon CLI
-
To publish a new version of a function
The following
publish-version
example publishes a new version of themy-function
Lambda function.aws lambda publish-version \ --function-name
my-function
Output:
{ "TracingConfig": { "Mode": "PassThrough" }, "CodeSha256": "dBG9m8SGdmlEjw/JYXlhhvCrAv5TxvXsbL/RMr0fT/I=", "FunctionName": "my-function", "CodeSize": 294, "RevisionId": "f31d3d39-cc63-4520-97d4-43cd44c94c20", "MemorySize": 128, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:3", "Version": "2", "Role": "arn:aws:iam::123456789012:role/service-role/MyTestFunction-role-zgur6bf4", "Timeout": 3, "LastModified": "2019-09-23T18:32:33.857+0000", "Handler": "my-function.handler", "Runtime": "nodejs10.x", "Description": "" }
For more information, see Configuring Amazon Lambda Function Aliases
in the Amazon Lambda Developer Guide. -
For API details, see PublishVersion
in Amazon CLI Command Reference.
-
The following code example shows how to use put-function-concurrency
.
- Amazon CLI
-
To configure a reserved concurrency limit for a function
The following
put-function-concurrency
example configures 100 reserved concurrent executions for themy-function
function.aws lambda put-function-concurrency \ --function-name
my-function
\ --reserved-concurrent-executions100
Output:
{ "ReservedConcurrentExecutions": 100 }
For more information, see Reserving Concurrency for a Lambda Function
in the Amazon Lambda Developer Guide. -
For API details, see PutFunctionConcurrency
in Amazon CLI Command Reference.
-
The following code example shows how to use put-function-event-invoke-config
.
- Amazon CLI
-
To configure error handling for asynchronous invocation
The following
put-function-event-invoke-config
example sets a maximum event age of one hour and disables retries for the specified function.aws lambda put-function-event-invoke-config \ --function-name
my-function
\ --maximum-event-age-in-seconds3600
\ --maximum-retry-attempts0
Output:
{ "LastModified": 1573686021.479, "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function:$LATEST", "MaximumRetryAttempts": 0, "MaximumEventAgeInSeconds": 3600, "DestinationConfig": { "OnSuccess": {}, "OnFailure": {} } }
-
For API details, see PutFunctionEventInvokeConfig
in Amazon CLI Command Reference.
-
The following code example shows how to use put-provisioned-concurrency-config
.
- Amazon CLI
-
To allocate provisioned concurrency
The following
put-provisioned-concurrency-config
example allocates 100 provisioned concurrency for theBLUE
alias of the specified function.aws lambda put-provisioned-concurrency-config \ --function-name
my-function
\ --qualifierBLUE
\ --provisioned-concurrent-executions100
Output:
{ "Requested ProvisionedConcurrentExecutions": 100, "Allocated ProvisionedConcurrentExecutions": 0, "Status": "IN_PROGRESS", "LastModified": "2019-11-21T19:32:12+0000" }
-
For API details, see PutProvisionedConcurrencyConfig
in Amazon CLI Command Reference.
-
The following code example shows how to use remove-layer-version-permission
.
- Amazon CLI
-
To delete layer-version permissions
The following
remove-layer-version-permission
example deletes permission for an account to configure a layer version.aws lambda remove-layer-version-permission \ --layer-name
my-layer
\ --statement-idxaccount
\ --version-number1
This command produces no output.
For more information, see Amazon Lambda Layers
in the Amazon Lambda Developer Guide. -
For API details, see RemoveLayerVersionPermission
in Amazon CLI Command Reference.
-
The following code example shows how to use remove-permission
.
- Amazon CLI
-
To remove permissions from an existing Lambda function
The following
remove-permission
example removes permission to invoke a function namedmy-function
.aws lambda remove-permission \ --function-name
my-function
\ --statement-idsns
This command produces no output.
For more information, see Using Resource-based Policies for Amazon Lambda
in the Amazon Lambda Developer Guide. -
For API details, see RemovePermission
in Amazon CLI Command Reference.
-
The following code example shows how to use tag-resource
.
- Amazon CLI
-
To add tags to an existing Lambda function
The following
tag-resource
example adds a tag with the key nameDEPARTMENT
and a value ofDepartment A
to the specified Lambda function.aws lambda tag-resource \ --resource
arn:aws:lambda:us-west-2:123456789012:function:my-function
\ --tags"DEPARTMENT=Department A"
This command produces no output.
For more information, see Tagging Lambda Functions
in the Amazon Lambda Developer Guide. -
For API details, see TagResource
in Amazon CLI Command Reference.
-
The following code example shows how to use untag-resource
.
- Amazon CLI
-
To remove tags from an existing Lambda function
The following
untag-resource
example removes the tag with the key nameDEPARTMENT
tag from themy-function
Lambda function.aws lambda untag-resource \ --resource
arn:aws:lambda:us-west-2:123456789012:function:my-function
\ --tag-keysDEPARTMENT
This command produces no output.
For more information, see Tagging Lambda Functions
in the Amazon Lambda Developer Guide. -
For API details, see UntagResource
in Amazon CLI Command Reference.
-
The following code example shows how to use update-alias
.
- Amazon CLI
-
To update a function alias
The following
update-alias
example updates the alias namedLIVE
to point to version 3 of themy-function
Lambda function.aws lambda update-alias \ --function-name
my-function
\ --function-version3
\ --nameLIVE
Output:
{ "FunctionVersion": "3", "Name": "LIVE", "AliasArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:LIVE", "RevisionId": "594f41fb-b85f-4c20-95c7-6ca5f2a92c93", "Description": "alias for live version of function" }
For more information, see Configuring Amazon Lambda Function Aliases
in the Amazon Lambda Developer Guide. -
For API details, see UpdateAlias
in Amazon CLI Command Reference.
-
The following code example shows how to use update-event-source-mapping
.
- Amazon CLI
-
To update the mapping between an event source and an Amazon Lambda function
The following
update-event-source-mapping
example updates the batch size to 8 in the specified mapping.aws lambda update-event-source-mapping \ --uuid
"a1b2c3d4-5678-90ab-cdef-11111EXAMPLE"
\ --batch-size8
Output:
{ "UUID": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "StateTransitionReason": "USER_INITIATED", "LastModified": 1569284520.333, "BatchSize": 8, "State": "Updating", "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "EventSourceArn": "arn:aws:sqs:us-west-2:123456789012:mySQSqueue" }
For more information, see Amazon Lambda Event Source Mapping
in the Amazon Lambda Developer Guide. -
For API details, see UpdateEventSourceMapping
in Amazon CLI Command Reference.
-
The following code example shows how to use update-function-code
.
- Amazon CLI
-
To update the code of a Lambda function
The following
update-function-code
example replaces the code of the unpublished ($LATEST) version of themy-function
function with the contents of the specified zip file.aws lambda update-function-code \ --function-name
my-function
\ --zip-filefileb://my-function.zip
Output:
{ "FunctionName": "my-function", "LastModified": "2019-09-26T20:28:40.438+0000", "RevisionId": "e52502d4-9320-4688-9cd6-152a6ab7490d", "MemorySize": 256, "Version": "$LATEST", "Role": "arn:aws:iam::123456789012:role/service-role/my-function-role-uy3l9qyq", "Timeout": 3, "Runtime": "nodejs10.x", "TracingConfig": { "Mode": "PassThrough" }, "CodeSha256": "5tT2qgzYUHaqwR716pZ2dpkn/0J1FrzJmlKidWoaCgk=", "Description": "", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "CodeSize": 304, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "Handler": "index.handler" }
For more information, see Amazon Lambda Function Configuration
in the Amazon Lambda Developer Guide. -
For API details, see UpdateFunctionCode
in Amazon CLI Command Reference.
-
The following code example shows how to use update-function-configuration
.
- Amazon CLI
-
To modify the configuration of a function
The following
update-function-configuration
example modifies the memory size to be 256 MB for the unpublished ($LATEST) version of themy-function
function.aws lambda update-function-configuration \ --function-name
my-function
\ --memory-size256
Output:
{ "FunctionName": "my-function", "LastModified": "2019-09-26T20:28:40.438+0000", "RevisionId": "e52502d4-9320-4688-9cd6-152a6ab7490d", "MemorySize": 256, "Version": "$LATEST", "Role": "arn:aws:iam::123456789012:role/service-role/my-function-role-uy3l9qyq", "Timeout": 3, "Runtime": "nodejs10.x", "TracingConfig": { "Mode": "PassThrough" }, "CodeSha256": "5tT2qgzYUHaqwR716pZ2dpkn/0J1FrzJmlKidWoaCgk=", "Description": "", "VpcConfig": { "SubnetIds": [], "VpcId": "", "SecurityGroupIds": [] }, "CodeSize": 304, "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function", "Handler": "index.handler" }
For more information, see Amazon Lambda Function Configuration
in the Amazon Lambda Developer Guide. -
For API details, see UpdateFunctionConfiguration
in Amazon CLI Command Reference.
-
The following code example shows how to use update-function-event-invoke-config
.
- Amazon CLI
-
To update an asynchronous invocation configuration
The following
update-function-event-invoke-config
example adds an on-failure destination to the existing asynchronous invocation configuration for the specified function.aws lambda update-function-event-invoke-config \ --function-name
my-function
\ --destination-config '{"OnFailure":{"Destination": "arn:aws:sqs:us-east-2:123456789012:destination"}}
'Output:
{ "LastModified": 1573687896.493, "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function:$LATEST", "MaximumRetryAttempts": 0, "MaximumEventAgeInSeconds": 3600, "DestinationConfig": { "OnSuccess": {}, "OnFailure": { "Destination": "arn:aws:sqs:us-east-2:123456789012:destination" } } }
-
For API details, see UpdateFunctionEventInvokeConfig
in Amazon CLI Command Reference.
-