Resource: awsLambdaLayerVersion
Provides a Lambda Layer Version resource. Lambda Layers allow you to reuse shared bits of code across multiple lambda functions.
For information about Lambda Layers and how to use them, see AWS Lambda Layers.
\~> NOTE: Setting skipDestroy
to true
means that the AWS Provider will not destroy any layer version, even when running terraformDestroy
. Layer versions are thus intentional dangling resources that are not managed by Terraform and may incur extra expense in your AWS account.
Example Usage
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lambdaLayerVersion.LambdaLayerVersion(this, "lambda_layer", {
compatibleRuntimes: ["nodejs16.x"],
filename: "lambda_layer_payload.zip",
layerName: "lambda_layer_name",
});
Specifying the Deployment Package
AWS Lambda Layers expect source code to be provided as a deployment package whose structure varies depending on which compatibleRuntimes
this layer specifies. See Runtimes for the valid values of compatibleRuntimes
.
Once you have created your deployment package you can specify it either directly as a local file (using the filename
argument) or indirectly via Amazon S3 (using the s3Bucket
, s3Key
and s3ObjectVersion
arguments). When providing the deployment package via S3 it may be useful to use the awsS3Object
resource to upload it.
For larger deployment packages it is recommended by Amazon to upload via S3, since the S3 API has better support for uploading large files efficiently.
Argument Reference
The following arguments are required:
layerName
- (Required) Unique name for your Lambda Layer
The following arguments are optional:
compatibleArchitectures
- (Optional) List of Architectures this layer is compatible with. Currentlyx8664
andarm64
can be specified.compatibleRuntimes
- (Optional) List of Runtimes this layer is compatible with. Up to 5 runtimes can be specified.description
- (Optional) Description of what your Lambda Layer does.filename
(Optional) Path to the function's deployment package within the local filesystem. If defined, Thes3
-prefixed options cannot be used.licenseInfo
- (Optional) License info for your Lambda Layer. See License Info.s3Bucket
- (Optional) S3 bucket location containing the function's deployment package. Conflicts withfilename
. This bucket must reside in the same AWS region where you are creating the Lambda function.s3Key
- (Optional) S3 key of an object containing the function's deployment package. Conflicts withfilename
.s3ObjectVersion
- (Optional) Object version containing the function's deployment package. Conflicts withfilename
.skipDestroy
- (Optional) Whether to retain the old version of a previously deployed Lambda Layer. Default isfalse
. When this is not set totrue
, changing any ofcompatibleArchitectures
,compatibleRuntimes
,description
,filename
,layerName
,licenseInfo
,s3Bucket
,s3Key
,s3ObjectVersion
, orsourceCodeHash
forces deletion of the existing layer version and creation of a new layer version.sourceCodeHash
- (Optional) Used to trigger updates. Must be set to a base64-encoded SHA256 hash of the package file specified with eitherfilename
ors3Key
. The usual way to set this is${filebase64Sha256("fileZip")}
(Terraform 0.11.12 or later) or${base64Sha256(file("fileZip"))}
(Terraform 0.11.11 and earlier), where "file.zip" is the local filename of the lambda layer source archive.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
arn
- ARN of the Lambda Layer with version.createdDate
- Date this resource was created.layerArn
- ARN of the Lambda Layer without version.signingJobArn
- ARN of a signing job.signingProfileVersionArn
- ARN for a signing profile version.sourceCodeSize
- Size in bytes of the function .zip file.version
- Lambda Layer version.
Import
Lambda Layers can be imported using arn
.