AWS Fundamentals Logo
AWS Fundamentals
AWS::Lambda::Function

Lambda Function

The AWS::Lambda::Function resource creates a Lambda function. To create a function, you need a [deployment package](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html) and an [execution role](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html). The deployment package is a .zip file archive or container image that contains your function code. The execution role grants the function permission to use AWS services, such as Amazon CloudWatch Logs for log streaming and AWS X-Ray for request tracing. You set the package type to Image if the deployment package is a [container image](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html). For these functions, include the URI of the container image in the ECR registry in the [ImageUri property of the Code property](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-imageuri). You do not need to specify the handler and runtime properties. You set the package type to Zip if the deployment package is a [.zip file archive](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html#gettingstarted-package-zip). For these functions, specify the S3 location of your .zip file in the Code property. Alternatively, for Node.js and Python functions, you can define your function inline in the [ZipFile property of the Code property](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-zipfile). In both cases, you must also specify the handler and runtime properties. You can use [code signing](https://docs.aws.amazon.com/lambda/latest/dg/configuration-codesigning.html) if your deployment package is a .zip file archive. To enable code signing for this function, specify the ARN of a code-signing configuration. When a user attempts to deploy a code package with UpdateFunctionCode, Lambda checks that the code package has a valid signature from a trusted publisher. The code-signing configuration includes a set of signing profiles, which define the trusted publishers for this function. When you update a AWS::Lambda::Function resource, CFNshort calls the [UpdateFunctionConfiguration](https://docs.aws.amazon.com/lambda/latest/api/API_UpdateFunctionConfiguration.html) and [UpdateFunctionCode](https://docs.aws.amazon.com/lambda/latest/api/API_UpdateFunctionCode.html)LAM APIs under the hood. Because these calls happen sequentially, and invocations can happen between these calls, your function may encounter errors in the time between the calls. For example, if you remove an environment variable, and the code that references that environment variable in the same CFNshort update, you may see invocation errors related to a missing environment variable. To work around this, you can invoke your function against a version or alias by default, rather than the $LATEST version. Note that you configure [provisioned concurrency](https://docs.aws.amazon.com/lambda/latest/dg/provisioned-concurrency.html) on a AWS::Lambda::Version or a AWS::Lambda::Alias. For a complete introduction to Lambda functions, see [What is Lambda?](https://docs.aws.amazon.com/lambda/latest/dg/lambda-welcome.html) in the *Lambda developer guide.*

Properties

31 configurable properties. 2 required. Click a row to see details.

Filter:
PropertyTypeFlags
Code
Code
Required
Role
string
Required
Architectures
Array<string>
CapacityProviderConfig
CapacityProviderConfig
CodeSigningConfigArn
string
DeadLetterConfig
DeadLetterConfig
Description
string
DurableConfig
DurableConfig
Environment
Environment
EphemeralStorage
EphemeralStorage
FileSystemConfigs
Array<FileSystemConfig>
FunctionName
string
Create-only
FunctionScalingConfig
FunctionScalingConfig
Handler
string
ImageConfig
ImageConfig
KmsKeyArn
string
Layers
Array<string>
LoggingConfig
LoggingConfig
MemorySize
integer
PackageType
string
Create-only
PublishToLatestPublished
boolean
Write-only
RecursiveLoop
string
ReservedConcurrentExecutions
integer
Runtime
string
RuntimeManagementConfig
RuntimeManagementConfig
SnapStart
SnapStart
Write-only
Tags
Array<Tag>
TenancyConfig
TenancyConfig
Create-only
Timeout
integer
TracingConfig
TracingConfig
VpcConfig
VpcConfig

Return Values

Values returned after the resource is created. Access these with Fn::GetAtt.

AttributeTypeDescription
Arnstring-
SnapStartResponseSnapStartResponse-

Sample CloudFormation Template

A minimal template with required properties and common optional ones.

template.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: Sample template for AWS::Lambda::Function

Resources:
  MyResource:
    Type: AWS::Lambda::Function
    Properties:
      Code: "value"
      Role: "value"
      Tags:
        - Key: Environment
          Value: Production
      Description: !Ref "AWS::StackName"

Required IAM Permissions

Permissions CloudFormation needs in your IAM role to manage this resource.

read

lambda:GetFunctionkms:Decryptlambda:GetFunctionCodeSigningConfiglambda:GetFunctionRecursionConfiglambda:GetRuntimeManagementConfiglambda:GetFunctionScalingConfig

create

lambda:CreateFunctionlambda:GetFunctionlambda:PutFunctionConcurrencyiam:PassRoles3:GetObjects3:GetObjectVersionec2:DescribeSecurityGroupsec2:DescribeSubnetsec2:DescribeVpcselasticfilesystem:DescribeMountTargetss3files:ListMountTargetskms:CreateGrantkms:Decryptkms:Encryptkms:GenerateDataKeylambda:GetCodeSigningConfiglambda:GetFunctionCodeSigningConfiglambda:GetLayerVersionlambda:GetRuntimeManagementConfiglambda:PutRuntimeManagementConfiglambda:TagResourcelambda:PutFunctionRecursionConfiglambda:GetFunctionRecursionConfiglambda:PutFunctionScalingConfiglambda:PassCapacityProvider

update

lambda:DeleteFunctionConcurrencylambda:GetFunctionlambda:PutFunctionConcurrencylambda:TagResourcelambda:UntagResourcelambda:UpdateFunctionConfigurationlambda:UpdateFunctionCodeiam:PassRoles3:GetObjects3:GetObjectVersionec2:DescribeSecurityGroupsec2:DescribeSubnetsec2:DescribeVpcselasticfilesystem:DescribeMountTargetss3files:ListMountTargetskms:CreateGrantkms:Decryptkms:GenerateDataKeylambda:GetRuntimeManagementConfiglambda:PutRuntimeManagementConfiglambda:PutFunctionCodeSigningConfiglambda:DeleteFunctionCodeSigningConfiglambda:GetCodeSigningConfiglambda:GetFunctionCodeSigningConfiglambda:PutFunctionRecursionConfiglambda:GetFunctionRecursionConfiglambda:PutFunctionScalingConfiglambda:PublishVersionlambda:PassCapacityProvider

list

lambda:ListFunctions

delete

lambda:DeleteFunctionlambda:GetFunctionec2:DescribeNetworkInterfaces

Get the Lambda Cheat Sheet

Everything you need to know about Lambda on one page. HD quality, print-friendly.

Download Free Infographic

Quick Facts

ServiceLambda
Properties33
Required2
TaggingSupported
Primary IDFunctionName

Supported Operations

ReadCreateUpdateListDelete

Immutable After Creation

These properties cannot be changed after the resource is created. Updating them triggers a replacement.

FunctionNamePackageTypeTenancyConfig

External Links