aws-cdk-lib.aws_lambda.LayerVersion

class LayerVersion (construct)

LanguageType name
.NETAmazon.CDK.AWS.Lambda.LayerVersion
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awslambda#LayerVersion
Javasoftware.amazon.awscdk.services.lambda.LayerVersion
Pythonaws_cdk.aws_lambda.LayerVersion
TypeScript (source)aws-cdk-lib » aws_lambda » LayerVersion

Implements IConstruct, IDependable, IResource, ILayerVersion

Defines a new Lambda Layer version.

Example

new lambda.LayerVersion(this, 'MyLayer', {
  removalPolicy: RemovalPolicy.RETAIN,
  code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
  compatibleArchitectures: [lambda.Architecture.X86_64, lambda.Architecture.ARM_64],
});

Initializer

new LayerVersion(scope: Construct, id: string, props: LayerVersionProps)

Parameters

  • scope Construct
  • id string
  • props LayerVersionProps

Construct Props

NameTypeDescription
codeCodeThe content of this Layer.
compatibleArchitectures?Architecture[]The system architectures compatible with this layer.
compatibleRuntimes?Runtime[]The runtimes compatible with this Layer.
description?stringThe description the this Lambda Layer.
layerVersionName?stringThe name of the layer.
license?stringThe SPDX licence identifier or URL to the license file for this layer.
removalPolicy?RemovalPolicyWhether to retain this version of the layer when a new version is added or when the stack is deleted.

code

Type: Code

The content of this Layer.

Using Code.fromInline is not supported.


compatibleArchitectures?

Type: Architecture[] (optional, default: [Architecture.X86_64])

The system architectures compatible with this layer.


compatibleRuntimes?

Type: Runtime[] (optional, default: All runtimes are supported.)

The runtimes compatible with this Layer.


description?

Type: string (optional, default: No description.)

The description the this Lambda Layer.


layerVersionName?

Type: string (optional, default: A name will be generated.)

The name of the layer.


license?

Type: string (optional, default: No license information will be recorded.)

The SPDX licence identifier or URL to the license file for this layer.


removalPolicy?

Type: RemovalPolicy (optional, default: RemovalPolicy.DESTROY)

Whether to retain this version of the layer when a new version is added or when the stack is deleted.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
layerVersionArnstringThe ARN of the Lambda Layer version that this Layer defines.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.
compatibleRuntimes?Runtime[]The runtimes compatible with this Layer.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


layerVersionArn

Type: string

The ARN of the Lambda Layer version that this Layer defines.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.


compatibleRuntimes?

Type: Runtime[] (optional)

The runtimes compatible with this Layer.

Methods

NameDescription
addPermission(id, permission)Add permission for this layer version to specific entities.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
toString()Returns a string representation of this construct.
static fromLayerVersionArn(scope, id, layerVersionArn)Imports a layer version by ARN.
static fromLayerVersionAttributes(scope, id, attrs)Imports a Layer that has been defined externally.

addPermission(id, permission)

public addPermission(id: string, permission: LayerVersionPermission): void

Parameters

  • id string
  • permission LayerVersionPermission

Add permission for this layer version to specific entities.

Usage within the same account where the layer is defined is always allowed and does not require calling this method. Note that the principal that creates the Lambda function using the layer (for example, a CloudFormation changeset execution role) also needs to have the lambda:GetLayerVersion permission on the layer version.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromLayerVersionArn(scope, id, layerVersionArn)

public static fromLayerVersionArn(scope: Construct, id: string, layerVersionArn: string): ILayerVersion

Parameters

  • scope Construct
  • id string
  • layerVersionArn string

Returns

  • ILayerVersion

Imports a layer version by ARN.

Assumes it is compatible with all Lambda runtimes.


static fromLayerVersionAttributes(scope, id, attrs)

public static fromLayerVersionAttributes(scope: Construct, id: string, attrs: LayerVersionAttributes): ILayerVersion

Parameters

  • scope Construct — the parent Construct that will use the imported layer.
  • id string — the id of the imported layer in the construct tree.
  • attrs LayerVersionAttributes — the properties of the imported layer.

Returns

  • ILayerVersion

Imports a Layer that has been defined externally.