aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code

Home Page:https://aws.amazon.com/cdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(aws-cdk-lib): (NodejsFunction & NestedStack)

TirushV opened this issue · comments

Describe the bug

When deploying NestedStack with NodejsFunction construct the entry of lambda function is actually taking wrong file. Its bundling the root folder of CDK and then trying to upload this on Lambda function (nodejs). This issue is open since 2 years (2022). Expecting it to be deployed with right entry point path file with nested stack.

REFER THIS OLD ISSUE - [#23181](https://github.com/aws/aws-cdk/issues/23181)

Expected Behavior

NodejsFunction should be deployed with correct entry file with NESTED STACK instead of bundling cdk root folder. (which is a very large file and fails due to this)

Current Behavior

Resource handler returned message: "Unzipped size must be smaller than 262144000 bytes (Service: Lambda, Status Code: 400, Request ID: 8a550035-ac30-4f04-8e5a-95ecf6e5b809)" (RequestToken: 4ed9ea28-2951-f1d3-232a-51a21ee23e53, HandlerErrorCode: InvalidRequest), Resource handler returned message: "Unzipped size must be smaller than 262144000 bytes

Reproduction Steps

Bin file

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { NestStack } from '../lib/nest-stack';

const app = new cdk.App();

interface stackProps {
  i: number;
}

export class FirstStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: stackProps) {
      super(scope, id);

      const { i } = props;
 
      for (let k = 0; k < props.i; k++) {
        new NestStack(this, `NestStack${k}`);
      }
  }
}
new FirstStack(app, 'TestStack', { i: 4 }); 

Nested stack file

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'
import { Runtime } from 'aws-cdk-lib/aws-lambda'
import * as path from 'path'

export class NestStack extends cdk.Stack {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    const lambdaAppDir = path.resolve(__dirname, '../lambda')

    const fn = new NodejsFunction(this, `function`, {
      functionName: 'test-function',
      runtime: Runtime.NODEJS_16_X,
      timeout: cdk.Duration.seconds(10),
      memorySize: 128,
      entry: path.join(lambdaAppDir, 'index.ts'),
    })
  }
}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.101.1 (build 16ddad1)

Framework Version

No response

Node.js Version

v18.13.0

OS

Sonoma 14.5 (Mac M2 Pro)

Language

TypeScript

Language Version

No response

Other information

No response

Hello @khushail , Appreciate the help here.

@TirushV , thanks for reaching out. Looks like you are deploying with an old version . Could you please try using the latest cdk version 2.147.0 and share updates if it still persists?

@khushail Tried (2.147.1 (build d3695d4)) that but no luck


node:internal/errors:491
    ErrorCaptureStackTrace(err);
    ^

RangeError [ERR_FS_FILE_TOO_LARGE]: File size (4360958549) is greater than 2 GiB
    at new NodeError (node:internal/errors:400:5)
    at readFileHandle (node:internal/fs/promises:448:11)
    at async Promise.all (index 0)
    at async /Users/tirush.venamadala/Desktop/news-protocol-backend/node_modules/aws-cdk/lib/index.js:417:64321 {
  code: 'ERR_FS_FILE_TOO_LARGE'
}

Node.js v18.13.0

It seems that cdk is bundling the whole root folder instead of lambda entry file. That the bug

Hey @TirushV , I tried to repro the issue as mentioned by you but did not see anything happening as such.

Could you please share more details I might be missing in reproduction of the issue ? where should I see the zipped package ?

Could you share the code snippet you tried? also which aws-cdk-lib version you had used. With the above code snippet when i try running the command - cdk deploy . Getting above error. Please let me know what details are required.

Main issue is its not zipping the file. Its trying to zip the whole cdk root folder.

@TirushV Good afternoon. Somehow, I'm unable to reproduce the issue. Below is the TypeScript CDK code:
/lambda/index.ts

exports.handler = async function() {
  return {
    statusCode: 200,
    headers: { "Content-Type": "text/plain" },
    body: 'Hello, CDK!'
  };
};

/lib/NestedStack.ts

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { Runtime, Architecture } from 'aws-cdk-lib/aws-lambda';
import * as path from 'path';

export class NestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const lambdaAppDir = path.resolve(__dirname, '../lambda');

    const fn = new NodejsFunction(this, `function`, {
      functionName: 'test-function',
      runtime: Runtime.NODEJS_16_X,
      timeout: cdk.Duration.seconds(10),
      memorySize: 128,
      architecture: Architecture.ARM_64,   // Used ARM_64 since running CDK Deploy on Apple M1 MacBook Pro
      entry: path.join(lambdaAppDir, 'index.ts'),
    });
  }
}

/bin/issue30627.ts

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { NestStack } from '../lib/NestStack';

const app = new cdk.App();

interface stackProps {
  i: number;
}

export class FirstStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: stackProps) {
      super(scope, id);

      const { i } = props;
 
      for (let k = 0; k < props.i; k++) {
        new NestStack(this, `NestStack${k}`);
      }
  }
}

new FirstStack(app, 'TestStack', { i: 4 });

Kindly note that in above code:

  • Architecture is set as Architecture.ARM_64 for Lambda function created in nested stack since the scenario is being run on Apple M1 Macbook Pro.
  • Lambda handler is pretty minimalistic. If you are using some complex logic that references some external module, then it might increase the Lambda deployment size.

Running cdk deploy --all produces the below output:

[+] Building 109.3s (14/14) FINISHED                                                                                                                                              docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                              0.0s
 => => transferring dockerfile: 1.36kB                                                                                                                                                            0.0s
 => [internal] load metadata for public.ecr.aws/sam/build-nodejs16.x:latest                                                                                                                       0.7s
 => [internal] load .dockerignore                                                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                                                   0.0s
 => [ 1/10] FROM public.ecr.aws/sam/build-nodejs16.x:latest@sha256:6d17355648b0f08271e16a4cd031ed469382aefc084de74afadb28fbb356273a                                                              34.3s
 => => resolve public.ecr.aws/sam/build-nodejs16.x:latest@sha256:6d17355648b0f08271e16a4cd031ed469382aefc084de74afadb28fbb356273a                                                                 0.0s
 => => sha256:a27b5bbb50a973e0b68cbf6e17651477554a7823940e39aa5c53ca54bca5d517 3.69kB / 3.69kB                                                                                                    0.0s
 => => sha256:abf716fb8e1fa0161050384d109f66932bf2b4c9fb47d0f24ea235547093ff68 417B / 417B                                                                                                        0.2s
 => => sha256:6d17355648b0f08271e16a4cd031ed469382aefc084de74afadb28fbb356273a 743B / 743B                                                                                                        0.0s
 => => sha256:e3749e77922e9505a333e49215a334f08cf0375b4e05b1a6e45c5d996d5e71c8 9.43kB / 9.43kB                                                                                                    0.0s
 => => sha256:f5cb5fa19ea34da404d84b1f84669301ac566bb234d214eaac51cebe07ca49c2 87.98kB / 87.98kB                                                                                                  0.2s
 => => sha256:10f19c591d574097fe01cc47d7714f3bf8a45d5e5cdb9ff4d28e9e5b202d1564 107.01MB / 107.01MB                                                                                                7.2s
 => => sha256:97123783274d402f12c320ea51bcaed38034299febb358deefce3d08f0ca756d 2.47MB / 2.47MB                                                                                                    0.7s
 => => sha256:f10ec30aa30e406979f32fb5d0a39be93482dfcc554be544f45bbdea82810781 34.92MB / 34.92MB                                                                                                  3.1s
 => => sha256:192f60367db24060a1082f42de33ccc0aa4f189881d8312c049370cf0ac86113 11.04MB / 11.04MB                                                                                                  1.5s
 => => sha256:7870ef5882dd7f9db55fc1eec8e7f1dbaaf73c31920a4e9253d6fdcfcd354335 312.13MB / 312.13MB                                                                                               21.8s
 => => sha256:08d0b1033c8c6a33d2b5c5fc64a7f0e4da37a2e66e61b27b99b98f1a751d07ac 25.02MB / 25.02MB                                                                                                  5.0s
 => => sha256:1b7fd5eab16417c948b66bd2130210b934b08e28927e3120a5c708f951e1dee3 56.60MB / 56.60MB                                                                                                  9.4s
 => => extracting sha256:10f19c591d574097fe01cc47d7714f3bf8a45d5e5cdb9ff4d28e9e5b202d1564                                                                                                         2.9s
 => => sha256:1da1b79280889a212173fb72b3005d3c03a2a817e5792e57434af61d11590156 71.10MB / 71.10MB                                                                                                 12.0s
 => => sha256:62d323463ba886d17a9982cc9124699b974b11fd0b7fb4a1fbf1fd801574478d 5.03kB / 5.03kB                                                                                                    9.6s
 => => sha256:540dbecb5bf3c055b82d499162a0bbe6e9ce1209d8971d7dbcc9707118e2359f 1.82MB / 1.82MB                                                                                                   10.1s
 => => sha256:d90b52b24bb6bbc326c1d6ef0f92a4c82aaa0803ee7bc0d775fa2dbe039d5e22 7.83MB / 7.83MB                                                                                                   10.8s
 => => extracting sha256:f5cb5fa19ea34da404d84b1f84669301ac566bb234d214eaac51cebe07ca49c2                                                                                                         0.0s
 => => extracting sha256:abf716fb8e1fa0161050384d109f66932bf2b4c9fb47d0f24ea235547093ff68                                                                                                         0.0s
 => => extracting sha256:97123783274d402f12c320ea51bcaed38034299febb358deefce3d08f0ca756d                                                                                                         0.0s
 => => sha256:6ecf9c24b2edbb0afc95235cda145e97ff3e11d8e824560f46084fc8e48392f3 178.15kB / 178.15kB                                                                                               11.0s
 => => extracting sha256:f10ec30aa30e406979f32fb5d0a39be93482dfcc554be544f45bbdea82810781                                                                                                         0.8s
 => => sha256:203f7abcbc9fd65cfdfd35ad7badd49970cf09586d3c4c3d3b8d65cd4f4c0f07 203.90kB / 203.90kB                                                                                               11.3s
 => => sha256:fc55c60433b9ec62b94437021dbacaf99d672febe8bd410a9dfd774a2ea8840d 122.19kB / 122.19kB                                                                                               11.4s
 => => extracting sha256:192f60367db24060a1082f42de33ccc0aa4f189881d8312c049370cf0ac86113                                                                                                         0.7s
 => => extracting sha256:7870ef5882dd7f9db55fc1eec8e7f1dbaaf73c31920a4e9253d6fdcfcd354335                                                                                                         7.0s
 => => extracting sha256:08d0b1033c8c6a33d2b5c5fc64a7f0e4da37a2e66e61b27b99b98f1a751d07ac                                                                                                         0.9s
 => => extracting sha256:1b7fd5eab16417c948b66bd2130210b934b08e28927e3120a5c708f951e1dee3                                                                                                         1.9s
 => => extracting sha256:1da1b79280889a212173fb72b3005d3c03a2a817e5792e57434af61d11590156                                                                                                         1.1s
 => => extracting sha256:62d323463ba886d17a9982cc9124699b974b11fd0b7fb4a1fbf1fd801574478d                                                                                                         0.0s
 => => extracting sha256:540dbecb5bf3c055b82d499162a0bbe6e9ce1209d8971d7dbcc9707118e2359f                                                                                                         0.0s
 => => extracting sha256:d90b52b24bb6bbc326c1d6ef0f92a4c82aaa0803ee7bc0d775fa2dbe039d5e22                                                                                                         0.3s
 => => extracting sha256:6ecf9c24b2edbb0afc95235cda145e97ff3e11d8e824560f46084fc8e48392f3                                                                                                         0.0s
 => => extracting sha256:203f7abcbc9fd65cfdfd35ad7badd49970cf09586d3c4c3d3b8d65cd4f4c0f07                                                                                                         0.0s
 => => extracting sha256:fc55c60433b9ec62b94437021dbacaf99d672febe8bd410a9dfd774a2ea8840d                                                                                                         0.0s
 => [ 2/10] RUN npm install --global yarn@1.22.5                                                                                                                                                  2.1s
 => [ 3/10] RUN npm install --global pnpm@7.30.5                                                                                                                                                  0.9s
 => [ 4/10] RUN npm install --global typescript                                                                                                                                                   0.9s
 => [ 5/10] RUN npm install --global --unsafe-perm=true esbuild@0.21                                                                                                                             68.9s
 => [ 6/10] RUN mkdir /tmp/npm-cache &&     chmod -R 777 /tmp/npm-cache &&     npm config --global set cache /tmp/npm-cache                                                                       0.3s
 => [ 7/10] RUN mkdir /tmp/yarn-cache &&     chmod -R 777 /tmp/yarn-cache &&     yarn config set cache-folder /tmp/yarn-cache                                                                     0.3s
 => [ 8/10] RUN mkdir /tmp/pnpm-cache &&     chmod -R 777 /tmp/pnpm-cache &&     pnpm config --global set store-dir /tmp/pnpm-cache                                                               0.4s
 => [ 9/10] RUN npm config --global set update-notifier false                                                                                                                                     0.3s
 => [10/10] RUN /sbin/useradd -u 1000 user && chmod 711 /                                                                                                                                         0.1s
 => exporting to image                                                                                                                                                                            0.1s
 => => exporting layers                                                                                                                                                                           0.1s
 => => writing image sha256:bc4199f88aa380bd8f467f902fe17c87f4c814fabedb3ec3ef4ac9051e0474b2                                                                                                      0.0s
 => => naming to docker.io/library/cdk-ec64e62a3f226016603df9d6301f029de6052cfbff6a4edca8fba753c7c96cb7                                                                                           0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/1jn5y84v4fm56t9lqtowzrbsu

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview 
Bundling asset TestStack/NestStack0/function/Code/Stage...
esbuild cannot run locally. Switching to Docker bundling.

  asset-output/index.js  194b 

⚡ Done in 6ms
[+] Building 0.3s (14/14) FINISHED                                                                                                                                                docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                              0.0s
 => => transferring dockerfile: 1.36kB                                                                                                                                                            0.0s
 => [internal] load metadata for public.ecr.aws/sam/build-nodejs16.x:latest                                                                                                                       0.3s
 => [internal] load .dockerignore                                                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                                                   0.0s
 => [ 1/10] FROM public.ecr.aws/sam/build-nodejs16.x:latest@sha256:6d17355648b0f08271e16a4cd031ed469382aefc084de74afadb28fbb356273a                                                               0.0s
 => CACHED [ 2/10] RUN npm install --global yarn@1.22.5                                                                                                                                           0.0s
 => CACHED [ 3/10] RUN npm install --global pnpm@7.30.5                                                                                                                                           0.0s
 => CACHED [ 4/10] RUN npm install --global typescript                                                                                                                                            0.0s
 => CACHED [ 5/10] RUN npm install --global --unsafe-perm=true esbuild@0.21                                                                                                                       0.0s
 => CACHED [ 6/10] RUN mkdir /tmp/npm-cache &&     chmod -R 777 /tmp/npm-cache &&     npm config --global set cache /tmp/npm-cache                                                                0.0s
 => CACHED [ 7/10] RUN mkdir /tmp/yarn-cache &&     chmod -R 777 /tmp/yarn-cache &&     yarn config set cache-folder /tmp/yarn-cache                                                              0.0s
 => CACHED [ 8/10] RUN mkdir /tmp/pnpm-cache &&     chmod -R 777 /tmp/pnpm-cache &&     pnpm config --global set store-dir /tmp/pnpm-cache                                                        0.0s
 => CACHED [ 9/10] RUN npm config --global set update-notifier false                                                                                                                              0.0s
 => CACHED [10/10] RUN /sbin/useradd -u 1000 user && chmod 711 /                                                                                                                                  0.0s
 => exporting to image                                                                                                                                                                            0.0s
 => => exporting layers                                                                                                                                                                           0.0s
 => => writing image sha256:bc4199f88aa380bd8f467f902fe17c87f4c814fabedb3ec3ef4ac9051e0474b2                                                                                                      0.0s
 => => naming to docker.io/library/cdk-ec64e62a3f226016603df9d6301f029de6052cfbff6a4edca8fba753c7c96cb7                                                                                           0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/c32y3ltcz5749drt354tdcs3v

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview 
[+] Building 0.1s (14/14) FINISHED                                                                                                                                                docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                              0.0s
 => => transferring dockerfile: 1.36kB                                                                                                                                                            0.0s
 => [internal] load metadata for public.ecr.aws/sam/build-nodejs16.x:latest                                                                                                                       0.1s
 => [internal] load .dockerignore                                                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                                                   0.0s
 => [ 1/10] FROM public.ecr.aws/sam/build-nodejs16.x:latest@sha256:6d17355648b0f08271e16a4cd031ed469382aefc084de74afadb28fbb356273a                                                               0.0s
 => CACHED [ 2/10] RUN npm install --global yarn@1.22.5                                                                                                                                           0.0s
 => CACHED [ 3/10] RUN npm install --global pnpm@7.30.5                                                                                                                                           0.0s
 => CACHED [ 4/10] RUN npm install --global typescript                                                                                                                                            0.0s
 => CACHED [ 5/10] RUN npm install --global --unsafe-perm=true esbuild@0.21                                                                                                                       0.0s
 => CACHED [ 6/10] RUN mkdir /tmp/npm-cache &&     chmod -R 777 /tmp/npm-cache &&     npm config --global set cache /tmp/npm-cache                                                                0.0s
 => CACHED [ 7/10] RUN mkdir /tmp/yarn-cache &&     chmod -R 777 /tmp/yarn-cache &&     yarn config set cache-folder /tmp/yarn-cache                                                              0.0s
 => CACHED [ 8/10] RUN mkdir /tmp/pnpm-cache &&     chmod -R 777 /tmp/pnpm-cache &&     pnpm config --global set store-dir /tmp/pnpm-cache                                                        0.0s
 => CACHED [ 9/10] RUN npm config --global set update-notifier false                                                                                                                              0.0s
 => CACHED [10/10] RUN /sbin/useradd -u 1000 user && chmod 711 /                                                                                                                                  0.0s
 => exporting to image                                                                                                                                                                            0.0s
 => => exporting layers                                                                                                                                                                           0.0s
 => => writing image sha256:bc4199f88aa380bd8f467f902fe17c87f4c814fabedb3ec3ef4ac9051e0474b2                                                                                                      0.0s
 => => naming to docker.io/library/cdk-ec64e62a3f226016603df9d6301f029de6052cfbff6a4edca8fba753c7c96cb7                                                                                           0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/kqjk5efub7pnbm4bblyp9hbmo

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview 
[+] Building 0.2s (14/14) FINISHED                                                                                                                                                docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                              0.0s
 => => transferring dockerfile: 1.36kB                                                                                                                                                            0.0s
 => [internal] load metadata for public.ecr.aws/sam/build-nodejs16.x:latest                                                                                                                       0.1s
 => [internal] load .dockerignore                                                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                                                   0.0s
 => [ 1/10] FROM public.ecr.aws/sam/build-nodejs16.x:latest@sha256:6d17355648b0f08271e16a4cd031ed469382aefc084de74afadb28fbb356273a                                                               0.0s
 => CACHED [ 2/10] RUN npm install --global yarn@1.22.5                                                                                                                                           0.0s
 => CACHED [ 3/10] RUN npm install --global pnpm@7.30.5                                                                                                                                           0.0s
 => CACHED [ 4/10] RUN npm install --global typescript                                                                                                                                            0.0s
 => CACHED [ 5/10] RUN npm install --global --unsafe-perm=true esbuild@0.21                                                                                                                       0.0s
 => CACHED [ 6/10] RUN mkdir /tmp/npm-cache &&     chmod -R 777 /tmp/npm-cache &&     npm config --global set cache /tmp/npm-cache                                                                0.0s
 => CACHED [ 7/10] RUN mkdir /tmp/yarn-cache &&     chmod -R 777 /tmp/yarn-cache &&     yarn config set cache-folder /tmp/yarn-cache                                                              0.0s
 => CACHED [ 8/10] RUN mkdir /tmp/pnpm-cache &&     chmod -R 777 /tmp/pnpm-cache &&     pnpm config --global set store-dir /tmp/pnpm-cache                                                        0.0s
 => CACHED [ 9/10] RUN npm config --global set update-notifier false                                                                                                                              0.0s
 => CACHED [10/10] RUN /sbin/useradd -u 1000 user && chmod 711 /                                                                                                                                  0.0s
 => exporting to image                                                                                                                                                                            0.0s
 => => exporting layers                                                                                                                                                                           0.0s
 => => writing image sha256:bc4199f88aa380bd8f467f902fe17c87f4c814fabedb3ec3ef4ac9051e0474b2                                                                                                      0.0s
 => => naming to docker.io/library/cdk-ec64e62a3f226016603df9d6301f029de6052cfbff6a4edca8fba753c7c96cb7                                                                                           0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/zske8ote35gegjm4cyp85fcp6

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview 
[Warning at /TestStack/NestStack0] Be aware that the NodeJS runtime of Node 16 will be deprecated by Lambda on June 12, 2024. Lambda runtimes Node 18 and higher include SDKv3 and not SDKv2. Updating your Lambda runtime will require bundling the SDK, or updating all SDK calls in your handler code to use SDKv3 (which is not a trivial update). Please account for this added complexity and update as soon as possible. [ack: aws-cdk-lib/aws-lambda-nodejs:runtimeUpdateSdkV2Breakage]
[Warning at /TestStack/NestStack1] Be aware that the NodeJS runtime of Node 16 will be deprecated by Lambda on June 12, 2024. Lambda runtimes Node 18 and higher include SDKv3 and not SDKv2. Updating your Lambda runtime will require bundling the SDK, or updating all SDK calls in your handler code to use SDKv3 (which is not a trivial update). Please account for this added complexity and update as soon as possible. [ack: aws-cdk-lib/aws-lambda-nodejs:runtimeUpdateSdkV2Breakage]
[Warning at /TestStack/NestStack2] Be aware that the NodeJS runtime of Node 16 will be deprecated by Lambda on June 12, 2024. Lambda runtimes Node 18 and higher include SDKv3 and not SDKv2. Updating your Lambda runtime will require bundling the SDK, or updating all SDK calls in your handler code to use SDKv3 (which is not a trivial update). Please account for this added complexity and update as soon as possible. [ack: aws-cdk-lib/aws-lambda-nodejs:runtimeUpdateSdkV2Breakage]
[Warning at /TestStack/NestStack3] Be aware that the NodeJS runtime of Node 16 will be deprecated by Lambda on June 12, 2024. Lambda runtimes Node 18 and higher include SDKv3 and not SDKv2. Updating your Lambda runtime will require bundling the SDK, or updating all SDK calls in your handler code to use SDKv3 (which is not a trivial update). Please account for this added complexity and update as soon as possible. [ack: aws-cdk-lib/aws-lambda-nodejs:runtimeUpdateSdkV2Breakage]

✨  Synthesis time: 116.32s

TestStack
TestStackNestStack0D4734FAF:  start: Building 12be3cf7df9d1327b0d47159e085530f12d130f7ed524e86e0a25c0a064a4511:current_account-current_region
TestStackNestStack0D4734FAF:  success: Built 12be3cf7df9d1327b0d47159e085530f12d130f7ed524e86e0a25c0a064a4511:current_account-current_region
TestStackNestStack19DF02A9C:  start: Building 460c693c04ab5013db62d786796a7bf02d72b8b4a49cdc15382439da61ddbc5a:current_account-current_region
TestStackNestStack19DF02A9C:  success: Built 460c693c04ab5013db62d786796a7bf02d72b8b4a49cdc15382439da61ddbc5a:current_account-current_region
TestStackNestStack0D4734FAF:  start: Publishing 12be3cf7df9d1327b0d47159e085530f12d130f7ed524e86e0a25c0a064a4511:current_account-current_region
TestStackNestStack253312563:  start: Building 7bc2368cf5af7f5431468ef40a3519b916bd67f9a567327c3a4e39f4cc86efa7:current_account-current_region
TestStackNestStack253312563:  success: Built 7bc2368cf5af7f5431468ef40a3519b916bd67f9a567327c3a4e39f4cc86efa7:current_account-current_region
TestStackNestStack19DF02A9C:  start: Publishing 460c693c04ab5013db62d786796a7bf02d72b8b4a49cdc15382439da61ddbc5a:current_account-current_region
TestStackNestStack253312563:  start: Publishing 7bc2368cf5af7f5431468ef40a3519b916bd67f9a567327c3a4e39f4cc86efa7:current_account-current_region
TestStackNestStack322E0A7D8:  start: Building ccf660faaf353398d78785a82c52602b13c4f47e534047a7973757216a3ac7bb:current_account-current_region
TestStackNestStack322E0A7D8:  success: Built ccf660faaf353398d78785a82c52602b13c4f47e534047a7973757216a3ac7bb:current_account-current_region
TestStackNestStack322E0A7D8:  start: Publishing ccf660faaf353398d78785a82c52602b13c4f47e534047a7973757216a3ac7bb:current_account-current_region
TestStack: deploying... [5/5]
TestStackNestStack322E0A7D8:  success: Published ccf660faaf353398d78785a82c52602b13c4f47e534047a7973757216a3ac7bb:current_account-current_region
TestStackNestStack19DF02A9C:  success: Published 460c693c04ab5013db62d786796a7bf02d72b8b4a49cdc15382439da61ddbc5a:current_account-current_region
TestStackNestStack253312563:  success: Published 7bc2368cf5af7f5431468ef40a3519b916bd67f9a567327c3a4e39f4cc86efa7:current_account-current_region

 ✅  TestStack (no changes)

✨  Deployment time: 0.56s

Stack ARN:
arn:aws:cloudformation:us-east-2:139480602983:stack/TestStack/77d80890-461c-11ef-991b-0a98a96128c9

✨  Total time: 116.88s

TestStack/NestStack3
TestStackNestStack0D4734FAF:  success: Published 12be3cf7df9d1327b0d47159e085530f12d130f7ed524e86e0a25c0a064a4511:current_account-current_region
This deployment will make potentially sensitive changes according to your current security approval level (--require-approval broadening).
Please confirm you intend to make the following modifications:

IAM Statement Changes
┌───┬────────────────────────────────────────┬────────┬────────────────┬──────────────────────────────┬───────────┐
│   │ Resource                               │ Effect │ Action         │ Principal                    │ Condition │
├───┼────────────────────────────────────────┼────────┼────────────────┼──────────────────────────────┼───────────┤
│ + │ ${NestStack3/function/ServiceRole.Arn} │ Allow  │ sts:AssumeRole │ Service:lambda.amazonaws.com │           │
└───┴────────────────────────────────────────┴────────┴────────────────┴──────────────────────────────┴───────────┘
IAM Policy Changes
┌───┬────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────┐
│   │ Resource                           │ Managed Policy ARN                                                             │
├───┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ + │ ${NestStack3/function/ServiceRole} │ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole │
└───┴────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────┘
(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)

Do you wish to deploy these changes (y/n)? y
TestStack/NestStack3: deploying... [4/5]
TestStackNestStack322E0A7D8: creating CloudFormation changeset...

 ✅  TestStack/NestStack3

✨  Deployment time: 39.36s

Stack ARN:
arn:aws:cloudformation:us-east-2:139480602983:stack/TestStackNestStack322E0A7D8/ea9756b0-461c-11ef-9863-0250818bb15b

✨  Total time: 155.68s

TestStack/NestStack1
This deployment will make potentially sensitive changes according to your current security approval level (--require-approval broadening).
Please confirm you intend to make the following modifications:

IAM Statement Changes
┌───┬────────────────────────────────────────┬────────┬────────────────┬──────────────────────────────┬───────────┐
│   │ Resource                               │ Effect │ Action         │ Principal                    │ Condition │
├───┼────────────────────────────────────────┼────────┼────────────────┼──────────────────────────────┼───────────┤
│ + │ ${NestStack1/function/ServiceRole.Arn} │ Allow  │ sts:AssumeRole │ Service:lambda.amazonaws.com │           │
└───┴────────────────────────────────────────┴────────┴────────────────┴──────────────────────────────┴───────────┘
IAM Policy Changes
┌───┬────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────┐
│   │ Resource                           │ Managed Policy ARN                                                             │
├───┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ + │ ${NestStack1/function/ServiceRole} │ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole │
└───┴────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────┘
(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)

Do you wish to deploy these changes (y/n)? y
TestStack/NestStack1: deploying... [2/5]
TestStackNestStack19DF02A9C: creating CloudFormation changeset...
3:20:53 PM | CREATE_FAILED        | AWS::Lambda::Function | functionF19B1A04
test-function already exists in stack arn:aws:cloudformation:us-east-2:139480602983:stack/TestStackNestStack322E0A7D8/ea9756b0-461c-11ef-9863-0250818bb15b


 ❌  TestStack/NestStack1 failed: Error: The stack named TestStackNestStack19DF02A9C failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: test-function already exists in stack arn:aws:cloudformation:us-east-2:139480602983:stack/TestStackNestStack322E0A7D8/ea9756b0-461c-11ef-9863-0250818bb15b
    at FullCloudFormationDeployment.monitorDeployment (/usr/local/lib/node_modules/aws-cdk/lib/index.js:455:10568)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.deployStack2 [as deployStack] (/usr/local/lib/node_modules/aws-cdk/lib/index.js:458:199716)
    at async /usr/local/lib/node_modules/aws-cdk/lib/index.js:458:181438

 ❌ Deployment failed: Error: The stack named TestStackNestStack19DF02A9C failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: test-function already exists in stack arn:aws:cloudformation:us-east-2:139480602983:stack/TestStackNestStack322E0A7D8/ea9756b0-461c-11ef-9863-0250818bb15b
    at FullCloudFormationDeployment.monitorDeployment (/usr/local/lib/node_modules/aws-cdk/lib/index.js:455:10568)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.deployStack2 [as deployStack] (/usr/local/lib/node_modules/aws-cdk/lib/index.js:458:199716)
    at async /usr/local/lib/node_modules/aws-cdk/lib/index.js:458:181438

The stack named TestStackNestStack19DF02A9C failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: test-function already exists in stack arn:aws:cloudformation:us-east-2:139480602983:stack/TestStackNestStack322E0A7D8/ea9756b0-461c-11ef-9863-0250818bb15b

The error above is different since there is already a function named test-function in first created nested stack. So your logic needs to be modified to create 4 different distinct Lambda functions, may be based on some identifier in custom cdk.StackProps for nested stack and using that identifier while setting function name.

If the issue still persists at your end, kindly share the minimal code solution (excluding the cdk.out and node_modules directory) to troubleshoot further.

Thanks,
Ashish

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.