A Lambda Layer is a .zip file archive that can contain additional code, pre-packaged dependencies, data, or configuration files. We provide a Lambda Layer for Powertools for AWS Lambda (TypeScript) to help you get started quickly with the library.
You can add our layer both in the AWS Lambda Console (under Layers), or via your favorite infrastructure as code framework with the ARN value. You can use the Lambda Layer both with CommonJS and ESM (ECMAScript modules).
You can also use AWS SSM Parameter Store to dynamically add Powertools for AWS Lambda. The {version} placeholder is the semantic version number (e,g. 2.1.0) for a release or _latest_.
For example, to get the ARN for version 2.14.0 in the eu-west-1 region, run the following command:
The pre-signed URL to download this Lambda Layer will be within Location key in the CLI output. The CLI output will also contain the Powertools for AWS Lambda version it contains.
Change {aws::region} to your AWS region, e.g. eu-west-1, and run the following command:
import{Stack}from'aws-cdk-lib';import{Construct}from'constructs';import{LayerVersion,Function,Runtime,Code}from'aws-cdk-lib/aws-lambda';import{NodejsFunction}from'aws-cdk-lib/aws-lambda-nodejs';exportclassSampleFunctionWithLayerextendsConstruct{constructor(scope:Construct,id:string){super(scope,id);// Create a Layer with Powertools for AWS Lambda (TypeScript)constpowertoolsLayer=LayerVersion.fromLayerVersionArn(this,'PowertoolsLayer',`arn:aws:lambda:${Stack.of(this).region}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:24`);newNodejsFunction(this,'Function',{runtime:Runtime.NODEJS_22_X,// Add the Layer to a Lambda functionlayers:[powertoolsLayer],code:Code.fromInline(`...`),handler:'index.handler',});}}
If you use esbuild to bundle your code, make sure to exclude @aws-lambda-powertools/* and @aws-sdk/* from being bundled since the packages are already present the layer:
Check the AWS CDK NodeJsFunctiondocumentation for more details.
You can also use AWS SSM Parameter Store to dynamically resolve the Layer ARN from SSM Parameter Store and add the toolkit in your code, allowing you to pin to latest or a specific Powertools for AWS version.
import{Stack}from'aws-cdk-lib';import{Construct}from'constructs';import{LayerVersion,Function,Runtime,Code}from'aws-cdk-lib/aws-lambda';import{NodejsFunction}from'aws-cdk-lib/aws-lambda-nodejs';import{StringParameter}from'aws-cdk-lib/aws-ssm';exportclassSampleFunctionWithLayerextendsConstruct{constructor(scope:Construct,id:string){super(scope,id);// Create a Layer with Powertools for AWS Lambda (TypeScript)constpowertoolsLayer=LayerVersion.fromLayerVersionArn(this,'PowertoolsLayer',StringParameter.valueForStringParameter(this,'PowertoolsLayer',{parameterName:'/aws/service/powertools/typescript/generic/all/latest',}));newNodejsFunction(this,'Function',{runtime:Runtime.NODEJS_22_X,// Add the Layer to a Lambda functionlayers:[powertoolsLayer],code:Code.fromInline(`...`),handler:'index.handler',});}}
You can also use AWS SSM Parameter Store to dynamically add Powertools for AWS Lambda and resolve the Layer ARN from SSM Parameter Store in your code, allowing you to pin to latest or a specific Powertools for AWS Lambda version.
If you use esbuild to bundle your code, make sure to exclude @aws-lambda-powertools/* and @aws-sdk/* from being bundled since the packages are already present the layer:
If you use esbuild to bundle your code, make sure to exclude @aws-lambda-powertools/* and @aws-sdk/* from being bundled since the packages are already present the layer:
You can use data sources to resolve the SSM Parameter Store in your code, allowing you to pin to latest or a specific Powertools for AWS Lambda version.
1 2 3 4 5 6 7 8 9101112
data"aws_ssm_parameter""powertools_version"{ # Replace {version} with your chosen Powertools for AWS Lambda version or latestname="/aws/service/powertools/python/generic/all/latest"}resource"aws_lambda_function""test_lambda"{...runtime="nodejs22.x"layers=[data.aws_ssm_parameter.powertools_version.value]}