Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_lambda_nodejs: default bundling option never bundle AWS SDK #32623

Open
cm-iwata opened this issue Dec 21, 2024 · 1 comment
Open

aws_lambda_nodejs: default bundling option never bundle AWS SDK #32623

cm-iwata opened this issue Dec 21, 2024 · 1 comment
Labels
@aws-cdk/aws-lambda-nodejs documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged.

Comments

@cm-iwata
Copy link
Contributor

Describe the issue

If deploy a NodejsFunction with code like the one below, the AWS SDK specified in package.json will not be bundled in the assets.

new nodejs.NodejsFunction(this, 'my-handler', {
 bundling: {
     network: 'host',
     securityOpt: 'no-new-privileges',
     user: 'user:group',
     volumesFrom: ['777f7dc92da7'],
     volumes: [{ hostPath: '/host-path', containerPath: '/container-path' }],
  },
});

As a result, our application will use the AWS SDK built into the Lambda execution environment by default.

The Lambda documentation states the following and recommends including the AWS SDK in your deployment package.

Control the dependencies in your function's deployment package. The AWS Lambda execution environment contains a number of libraries. For the Node.js and Python runtimes, these include the AWS SDKs. To enable the latest set of features and security updates, Lambda will periodically update these libraries. These updates may introduce subtle changes to the behavior of your Lambda function. To have full control of the dependencies your function uses, package all of your dependencies with your deployment package.

https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html#nodejs-best-practices

The default bundling options may break AWS SDK compatibility, so I think the CDK documentation should also clearly warn about this.

Links

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.BundlingOptions.html

@cm-iwata cm-iwata added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Dec 21, 2024
@nmussy
Copy link
Contributor

nmussy commented Dec 21, 2024

This is very fair, the intended meaning of "package all of your dependencies" is not to just list them in your package.json, but to use a bundler like esbuild or webpack yourself instead of having the CDK create the bundle. "Bundling your dependencies" might be clearer and avoid the confusion between packaging and package.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants