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: missing aws-sdk-v3 libs at runtime #23873

Closed
dambaron opened this issue Jan 27, 2023 · 7 comments
Closed

@aws-lambda-nodejs: missing aws-sdk-v3 libs at runtime #23873

dambaron opened this issue Jan 27, 2023 · 7 comments
Labels
@aws-cdk/aws-lambda-nodejs effort/small Small work item – less than a day of effort p2 wontfix We have determined that we will not resolve the issue.

Comments

@dambaron
Copy link

Describe the bug

After bumping aws-cdk & aws-cdk-lib from 2.51.1 to 2.62.1 multiple lambdas are failing while performing DynamoDB calls.

The log messages look like:

{type: "INTERNAL_SERVER_ERROR", message: "Cannot read properties of undefined (reading 'ALL_NEW')"}

message:  "Cannot read properties of undefined (reading 'ALL_NEW')"

type: "INTERNAL_SERVER_ERROR"

All lambda perform similar DynamoDB commands like this :

const updateCommand = new UpdateCommand({
      ...
      ReturnValues: ReturnValue.ALL_NEW,
 })

It seems like that the ReturnValue enum is missing from the package asset.
It is confirmed by the fact that the package asset went from 900ko to 300ko and the announcement that the aws-sdk-v3 is now included within the NodeJs runtime.

Knowing that, how should the lambdas be packages to avoid this behavior ?

Expected Behavior

The aws-sdk-v3 libs should be bundled in the lambda asset and / or be available at runtime.

Current Behavior

The aws-sdk-v3 libs are not available at runtime

Reproduction Steps

Build a Node.js lambda with the 18.x runtime and perform a simple DynamoDB update

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.62.1

Framework Version

No response

Node.js Version

v18.12.1

OS

N/A

Language

Typescript

Language Version

4.9.4

Other information

No response

@dambaron dambaron added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 27, 2023
@mattiamatrix
Copy link
Contributor

mattiamatrix commented Jan 27, 2023

I also have issues with aws-sdk-v3 and enums. I am having the same problem with StandardUnit.Count from @aws-sdk/client-cloudwatch.

I think it was introduced with 2.54.0 linked to #22989

@mrgrain
Copy link
Contributor

mrgrain commented Jan 27, 2023

@dambaron @mattiamatrix To confirm, you are using the NodejsFunction construct to create AWS Lambda Functions with the nodejs18.x runtime?


The nodejs18.x runtime has the SDK with version 3.188.0 built-in. If you need any version other than this, you will have to bundle the SDK code.
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

You can set the bundling.externalModules property to an empty array [] to always bundle the local version of the SDK.
See: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.BundlingOptions.html#externalmodules

@mattiamatrix
Copy link
Contributor

Yep, looks like it works again with

const bundling: BundlingOptions = {
    minify: true,
    sourceMap: true,
    externalModules: [],
};

Feeling like a breaking change. Not impressed with this change.

@mrgrain
Copy link
Contributor

mrgrain commented Jan 27, 2023

Feeling like a breaking change. Not impressed with this change.

I can understand where you are coming from. From our perspective NodejsFunction by default does not bundle the SDK already available in Lambda. That was documented, but explicitly only for SDK v2. The SDK change in the Node18 lambda caught us off guard and was missed when originally adding Node 18 support.

I'll take your feedback on for future changes.

@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 7, 2023
@mattiamatrix
Copy link
Contributor

Thank you @mrgrain. But I am still very confused by the behaviour here.
Looking at https://github.com/aws/aws-cdk/blob/main/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts#L127-L130 doesn't help either.

Looking at @peterwoodworth changes to the tags, it seems like something needs to be done. Correct?

@mrgrain
Copy link
Contributor

mrgrain commented Feb 20, 2023

Hey @mattiamatrix Sorry this behavior isn't clear yet. Does the docstring help at all?

A list of modules that should be considered as externals (already available
in the runtime).

@default - ['aws-sdk'] if the runtime is < Node.js 18.x, ['@aws-sdk/*'] otherwise.

Another way of saying this could be: "By default NodejsFunction excludes the major SDK version that is provided with the Runtime version. For a list of Runtime and SDK versions, see: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html"

We are very open to improving the docs in this regard.


Regarding the tags Peter added - this is on me. I meant to close the issue after a bit and forgot to do this. I have done this now.

@mrgrain mrgrain added wontfix We have determined that we will not resolve the issue. and removed bug This issue is a bug. labels Feb 20, 2023
@mrgrain mrgrain closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs effort/small Small work item – less than a day of effort p2 wontfix We have determined that we will not resolve the issue.
Projects
None yet
Development

No branches or pull requests

4 participants