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

Lambda embedded SDK doesn't work alongside bundled node modules #4225

Closed
3 tasks done
paul-uz opened this issue Nov 24, 2022 · 4 comments
Closed
3 tasks done

Lambda embedded SDK doesn't work alongside bundled node modules #4225

paul-uz opened this issue Nov 24, 2022 · 4 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@paul-uz
Copy link

paul-uz commented Nov 24, 2022

Checkboxes for prior research

Describe the bug

SDK v3 is embedded in the Node 18 Lambda image. But it does not work if you have a function with a package file and node_modules folder eg your function uses embedded AWS SDK for a database query, and uses a third party library like MomentJS.

SDK version number

latest

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node 18

Reproduction Steps

Create simple function, using a v3 SDK eg lib-dynamodb. Add a single 3rd party module eg MomentJS.

The function won't be able to load lib-dynamodb.

Remove the MomemtJS usage and just have the Js file in the function, it should now be able to use lib-dynamodb successfully.

Observed Behavior

Canot use the embedded v3 SDK when also using 3rd party modules.

Expected Behavior

Should be able to use embedded SDK and additional modules

Possible Solution

No response

Additional Information/Context

No response

@paul-uz paul-uz added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 24, 2022
@jtuliani
Copy link

@paul-uz Please can you provide more details to allow us to reproduce what you are seeing?

From our testing (function zip file includes node_modules with moment in it), ESM works:

import { S3Client } from "@aws-sdk/client-s3";
import * as moment from 'moment';

export const handler = async (e, c) => {
    console.log('S3Client', S3Client);
    console.log('moment', moment.default(new Date()).format());
}
2022-11-25T11:18:40.219Z	c5296dcf-d8b3-414b-92c8-6d9c8bb3345c	INFO	S3Client [class S3Client extends Client]
2022-11-25T11:18:40.270Z	c5296dcf-d8b3-414b-92c8-6d9c8bb3345c	INFO	moment 2022-11-25T11:18:40+00:00

And CJS works:

const { S3Client } = require("@aws-sdk/client-s3");
const moment = require('moment');

module.exports.handler = async (e, c) => {
    console.log('S3Client', S3Client);
    console.log('moment', moment().format());
}
2022-11-25T11:22:55.379Z	44a976db-3c49-40df-9e9b-31580b525a58	INFO	S3Client [class S3Client extends Client]
2022-11-25T11:22:55.439Z	44a976db-3c49-40df-9e9b-31580b525a58	INFO	moment 2022-11-25T11:22:55+00:00

@paul-uz
Copy link
Author

paul-uz commented Nov 25, 2022

@paul-uz Please can you provide more details to allow us to reproduce what you are seeing?

From our testing (function zip file includes node_modules with moment in it), ESM works:

import { S3Client } from "@aws-sdk/client-s3";
import * as moment from 'moment';

export const handler = async (e, c) => {
    console.log('S3Client', S3Client);
    console.log('moment', moment.default(new Date()).format());
}
2022-11-25T11:18:40.219Z	c5296dcf-d8b3-414b-92c8-6d9c8bb3345c	INFO	S3Client [class S3Client extends Client]
2022-11-25T11:18:40.270Z	c5296dcf-d8b3-414b-92c8-6d9c8bb3345c	INFO	moment 2022-11-25T11:18:40+00:00

And CJS works:

const { S3Client } = require("@aws-sdk/client-s3");
const moment = require('moment');

module.exports.handler = async (e, c) => {
    console.log('S3Client', S3Client);
    console.log('moment', moment().format());
}
2022-11-25T11:22:55.379Z	44a976db-3c49-40df-9e9b-31580b525a58	INFO	S3Client [class S3Client extends Client]
2022-11-25T11:22:55.439Z	44a976db-3c49-40df-9e9b-31580b525a58	INFO	moment 2022-11-25T11:22:55+00:00

It's not about ESM or CommonJD, it's about having the local package file and node modules folder.

Try running a function that just uses the AWS SDK and nothing else, using the embedded SDK in the lambda. It will work. Now add in moment, and add the package.json (containing only momentjs) and node modules folder to the function. The call using the AWS SDK won't work.

@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Nov 27, 2022
@yenfryherrerafeliz yenfryherrerafeliz removed the needs-triage This issue or PR still needs to be triaged. label Nov 28, 2022
@yenfryherrerafeliz yenfryherrerafeliz added the p2 This is a standard priority issue label Feb 10, 2023
@yenfryherrerafeliz
Copy link
Contributor

Hi @paul-uz, this seems to be fixed on lambda side. I just did a test and it worked just fine for me. In any case I feel that this issue was related to lambda itself and not with the SDK.

I will resolve this issue for now, but please feel free of opening a new issue if is there anything else that we can help with.

Thanks!

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants