AWS::Serverless::LayerVersion
Creates a Lambda LayerVersion that contains library or runtime code needed by a Lambda Function.
The AWS::Serverless::LayerVersion resource also supports the Metadata
resource attribute, so you can instruct Amazon SAM to build layers included in your application. For more information about building layers, see Building layers.
Important Note: Since the release of the UpdateReplacePolicy resource attribute in Amazon CloudFormation, AWS::Lambda::LayerVersion (recommended) offers the same benefits as AWS::Serverless::LayerVersion.
When a Serverless LayerVersion is transformed, SAM also transforms the logical id of the resource so that old LayerVersions are not automatically deleted by CloudFormation when the resource is updated.
Note
When you deploy to Amazon CloudFormation, Amazon SAM transforms your Amazon SAM resources into Amazon CloudFormation resources. For more information, see Generated Amazon CloudFormation resources.
Syntax
To declare this entity in your Amazon Serverless Application Model (Amazon SAM) template, use the following syntax.
YAML
Type: AWS::Serverless::LayerVersion Properties: CompatibleArchitectures:
List
CompatibleRuntimes:List
ContentUri:String | LayerContent
Description:String
LayerName:String
LicenseInfo:String
RetentionPolicy:String
Properties
-
CompatibleArchitectures
-
Specifies the supported instruction set architectures for the layer version.
For more information about this property, see Lambda instruction set architectures in the Amazon Lambda Developer Guide.
Valid values:
x86_64
,arm64
Type: List
Required: No
Default:
x86_64
Amazon CloudFormation compatibility: This property is passed directly to the
CompatibleArchitectures
property of anAWS::Lambda::LayerVersion
resource. -
CompatibleRuntimes
-
List of runtimes compatible with this LayerVersion.
Type: List
Required: No
Amazon CloudFormation compatibility: This property is passed directly to the
CompatibleRuntimes
property of anAWS::Lambda::LayerVersion
resource. -
ContentUri
-
Amazon S3 Uri, path to local folder, or LayerContent object of the layer code.
If an Amazon S3 Uri or LayerContent object is provided, The Amazon S3 object referenced must be a valid ZIP archive that contains the contents of an Lambda layer.
If a path to a local folder is provided, for the content to be transformed properly the template must go through the workflow that includes sam build followed by either sam deploy or sam package. By default, relative paths are resolved with respect to the Amazon SAM template's location.
Type: String | LayerContent
Required: Yes
Amazon CloudFormation compatibility: This property is similar to the
Content
property of anAWS::Lambda::LayerVersion
resource. The nested Amazon S3 properties are named differently. -
Description
-
Description of this layer.
Type: String
Required: No
Amazon CloudFormation compatibility: This property is passed directly to the
Description
property of anAWS::Lambda::LayerVersion
resource. -
LayerName
-
The name or Amazon Resource Name (ARN) of the layer.
Type: String
Required: No
Default: Resource logical id
Amazon CloudFormation compatibility: This property is similar to the
LayerName
property of anAWS::Lambda::LayerVersion
resource. If you don't specify a name, the logical id of the resource will be used as the name. -
LicenseInfo
-
Information about the license for this LayerVersion.
Type: String
Required: No
Amazon CloudFormation compatibility: This property is passed directly to the
LicenseInfo
property of anAWS::Lambda::LayerVersion
resource. -
RetentionPolicy
-
This property specifies whether old versions of your
LayerVersion
are retained or deleted when you delete a resource. If you need to retain old versions of yourLayerVersion
when updating or replacing a resource, you must have theUpdateReplacePolicy
attribute enabled. For information on doing this, refer toUpdateReplacePolicy
attribute in the Amazon CloudFormation User Guide.Valid values:
Retain
orDelete
Type: String
Required: No
Amazon CloudFormation compatibility: This property is unique to Amazon SAM and doesn't have an Amazon CloudFormation equivalent.
Additional notes: When you specify
Retain
, Amazon SAM adds a Resource attributes ofDeletionPolicy: Retain
to the transformedAWS::Lambda::LayerVersion
resource.
Return Values
Ref
When the logical ID of this resource is provided to the Ref
intrinsic function, it returns the resource ARN of the underlying Lambda LayerVersion.
For more information about using the Ref
function, see Ref
in the Amazon CloudFormation User Guide.
Examples
LayerVersionExample
Example of a LayerVersion
YAML
Properties: LayerName: MyLayer Description: Layer description ContentUri: 's3://my-bucket/my-layer.zip' CompatibleRuntimes: - nodejs10.x - nodejs12.x LicenseInfo: 'Available under the MIT-0 license.' RetentionPolicy: Retain