diff --git a/docs/getting-started/lambda-layers.md b/docs/getting-started/lambda-layers.md index 4ba544475a..3ff440555c 100644 --- a/docs/getting-started/lambda-layers.md +++ b/docs/getting-started/lambda-layers.md @@ -154,7 +154,7 @@ Change `{aws::region}` to your AWS region, e.g. `eu-west-1`, and run the followi } ``` - 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/*` from being bundled since the packages are already present in the layer: ```typescript new NodejsFunction(this, 'Function', { @@ -162,7 +162,6 @@ Change `{aws::region}` to your AWS region, e.g. `eu-west-1`, and run the followi bundling: { externalModules: [ '@aws-lambda-powertools/*', - '@aws-sdk/*', ], } }); @@ -223,7 +222,7 @@ Change `{aws::region}` to your AWS region, e.g. `eu-west-1`, and run the followi - {{resolve:ssm:/aws/service/powertools/typescript/generic/all/latest}} ``` - 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/*` from being bundled since the packages are already present in the layer: ```yaml hl_lines="5-14" MyLambdaFunction: @@ -237,7 +236,6 @@ Change `{aws::region}` to your AWS region, e.g. `eu-west-1`, and run the followi Minify: true External: - '@aws-lambda-powertools/*' - - '@aws-sdk/*' ``` Check the [documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build-typescript.html) for more details. @@ -252,14 +250,13 @@ Change `{aws::region}` to your AWS region, e.g. `eu-west-1`, and run the followi - arn:aws:lambda:${aws:region}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:49 ``` - 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/*` from being bundled since the packages are already present in the layer: ```yaml custom: esbuild: external: - '@aws-lambda-powertools/*' - - '@aws-sdk/*' ``` Check the [documentation](https://floydspace.github.io/serverless-esbuild/) for more details. @@ -364,3 +361,16 @@ npm i -D @aws-lambda-powertools/logger - **Version synchronization**: Keep your local development dependencies in sync with the Lambda Layer version to maintain consistency Following these practices prevents version conflicts that can cause unexpected behavior, such as failed `instanceof` checks or inconsistent behavior between your local development environment and the Lambda execution environment. + +???+ note "AWS SDK v3 is no longer included in the layer" + + Layer version `49` is the last one to bundle AWS SDK v3 clients; later + versions do not include any `@aws-sdk/*` package. + + The layer is mounted at `/opt/nodejs/node_modules`, which takes precedence + over the runtime's own copy, so the bundled clients were picked up by your + function code as well. Since the layer only ever included a subset of the + SDK, this could leave you with mismatched SDK packages at runtime. + + Install the clients your code needs as regular dependencies and bundle them + with your function, or rely on the copy the Lambda Node.js runtime provides. diff --git a/layers/src/layer-publisher-stack.ts b/layers/src/layer-publisher-stack.ts index 054f66214c..7ed00b9227 100644 --- a/layers/src/layer-publisher-stack.ts +++ b/layers/src/layer-publisher-stack.ts @@ -107,15 +107,19 @@ export class LayerPublisherStack extends Stack { 'node_modules/@aws-sdk/**/README.md ', ]; const buildCommands: string[] = []; - // We install these to get the latest version of the packages - const modulesToInstall: string[] = [ - '@aws-sdk/client-dynamodb', - '@aws-sdk/util-dynamodb', - '@aws-sdk/client-ssm', - '@aws-sdk/client-secrets-manager', - '@aws-sdk/client-appconfigdata', - 'zod', - ]; + // We deliberately do NOT ship any @aws-sdk/* client in the layer. + // + // The layer is mounted at /opt/nodejs/node_modules, which precedes + // /var/runtime/node_modules on NODE_PATH. Any SDK package we ship + // therefore shadows the runtime's copy for customer code too. Since + // we only ever shipped a subset (e.g. client-dynamodb but never + // lib-dynamodb), customers using the DocumentClient ended up with a + // layer-provided client and a runtime-provided lib, and any breaking + // change across that boundary surfaces as a runtime error. + // + // The Node.js runtime already provides a complete, self-consistent + // AWS SDK v3, so we rely on it instead of exposing a partial one. + const modulesToInstall: string[] = ['zod']; if (buildFromLocal) { for (const util of utilities) {