class LayerVersion (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Lambda.LayerVersion |
Java | software.amazon.awscdk.services.lambda.LayerVersion |
Python | aws_cdk.aws_lambda.LayerVersion |
TypeScript (source) | @aws-cdk/aws-lambda » LayerVersion |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, ILayer
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
Layer
Version Props
Construct Props
Name | Type | Description |
---|---|---|
code | Code | The content of this Layer. |
compatible | Architecture [] | The system architectures compatible with this layer. |
compatible | Runtime [] | The runtimes compatible with this Layer. |
description? | string | The description the this Lambda Layer. |
layer | string | The name of the layer. |
license? | string | The SPDX licence identifier or URL to the license file for this layer. |
removal | Removal | Whether 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:
Removal
(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
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
layer | string | The ARN of the Lambda Layer version that this Layer defines. |
node | Construct | The construct tree node associated with this construct. |
stack | Stack | The stack in which this resource is defined. |
compatible | Runtime [] | The runtimes compatible with this Layer. |
env
Type:
Resource
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:
Construct
The construct tree node associated with this construct.
stack
Type:
Stack
The stack in which this resource is defined.
compatibleRuntimes?
Type:
Runtime
[]
(optional)
The runtimes compatible with this Layer.
Methods
Name | Description |
---|---|
add | Add permission for this layer version to specific entities. |
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | Imports a layer version by ARN. |
static from | Imports a Layer that has been defined externally. |
Permission(id, permission)
addpublic addPermission(id: string, permission: LayerVersionPermission): void
Parameters
- id
string
- permission
Layer
Version Permission
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.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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
).
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
LayerVersionArn(scope, id, layerVersionArn)
static frompublic static fromLayerVersionArn(scope: Construct, id: string, layerVersionArn: string): ILayerVersion
Parameters
- scope
Construct
- id
string
- layerVersionArn
string
Returns
Imports a layer version by ARN.
Assumes it is compatible with all Lambda runtimes.
LayerVersionAttributes(scope, id, attrs)
static frompublic 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
Layer
— the properties of the imported layer.Version Attributes
Returns
Imports a Layer that has been defined externally.