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 with Node 18.x and SDK v3 throws errors #213

Closed
joelrwilliams12 opened this issue Nov 19, 2022 · 16 comments · Fixed by #216
Closed

AWS Lambda with Node 18.x and SDK v3 throws errors #213

joelrwilliams12 opened this issue Nov 19, 2022 · 16 comments · Fixed by #216

Comments

@joelrwilliams12
Copy link

joelrwilliams12 commented Nov 19, 2022

Currently lambda-api loads 'aws-sdk' in /lib/s3-service.js.

This fails with Node.js 18.x Lambda functions which are pre-loaded with SDK v3 and requires new syntax for loading SDK modules.

This throws the following error:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'aws-sdk'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'aws-sdk'",
        "Require stack:",
        "- /var/task/index.js",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:1000:17)",
        "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:21)",
        "    at async start (file:///var/runtime/index.mjs:1200:23)",
        "    at async file:///var/runtime/index.mjs:1206:1"
    ]
}

New syntax should be something like:

import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { S3Client, getSignedUrl, GetObjectCommand } from "@aws-sdk/client-s3";

Documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_s3_request_presigner.html

@joelrwilliams12 joelrwilliams12 changed the title AWS Lambda 18.x with SDK v3 throws errors AWS Lambda with Node 18.x and SDK v3 throws errors Nov 19, 2022
@QAnders
Copy link

QAnders commented Dec 6, 2022

I hate ESM and that we are forced to upgrade to it, and apparently AWS has taken that path as well with Node18 and SDK V3... :(

Even though CJS modules should be backwards compatible, they seldom are when it comes to "frameworks", e.g. Serverless and all it's plugins.
This puts us in a difficult position as we have dependencies that are still CJS only but other forces (e.g. AWS) forces us to ESM.

Sure, ESM will win out essentially but it's kind of like BetaMax won over VHS in the 90'ies... We are being forces to move on...

I'd appreciate if this could be done like other module vendors have, leave the current version (maintained) as CJS, and in case you adopt ESM, create a new major version that will be ESM moving forward...

Thanks for the great package!

@AndrewBarba
Copy link
Contributor

@QAnders This has nothing to do with ESM. The nodejs18.x runtime does not bundle the package aws-sdk, the v2 sdk. Instead it bundles @aws-sdk/**/* which is the v3 version of the sdk. Fixing this issue would simply involve updating lambda-api to require the v3 variants of the sdk instead of the v2 variants. No need to switch to ESM

@AndrewBarba
Copy link
Contributor

PR: #216

@slootjes
Copy link

When could this PR be merged?

@naorpeled
Copy link
Collaborator

Hey everyone,
I'll go over all the open issues and see what can be pushed in the next iteration.

afterwards, I'm planning on upgrading the usage of the AWS SDK to v3 + making the lib fully with TS, instead of separate declaration files.

Will keep you updated 🙏

@lucas-subli
Copy link

Just tried to update to Node 18 yesterday 😅

Looking forward for the update.

@muralimanohars
Copy link

Hey, When do we expect upgraded version with AWS SDK v3?

@naorpeled
Copy link
Collaborator

naorpeled commented Feb 24, 2023

Hey, When do we expect upgraded version with AWS SDK v3?

Hey,
been super super busy couple of weeks at work,
going on vacation on Wednesday, will probably start working on it on Thursday/Friday and keep you guys posted.

Sorry that it's taking longer than anticipated 🙏

@AndrewBarba
Copy link
Contributor

@naorpeled any reason you wouldn't merge the PR I put up?

@naorpeled
Copy link
Collaborator

@naorpeled any reason you wouldn't merge the PR I put up?

No, will review it asap :)

@naorpeled naorpeled linked a pull request Mar 9, 2023 that will close this issue
@naorpeled
Copy link
Collaborator

naorpeled commented Mar 9, 2023

Hey everyone,
the move of the S3 service to AWS SDK 3 is now in main,
I want to make some small adjustments before releasing v1,
will release it asap!

@joelrwilliams12
Copy link
Author

thanks so much this update...just updated the package on one of my Lambda functions and it's running with Node 18.x just fine! ❤️

@naorpeled
Copy link
Collaborator

thanks so much this update...just updated the package on one of my Lambda functions and it's running with Node 18.x just fine! ❤️

Awesome!!

@slootjes
Copy link

slootjes commented Mar 9, 2023

Amazing! I will give it a try next week. Thanks in advance for your hard work!

@muralimanohars
Copy link

Thanks for the update. It is working fine with Node 18

@lucas-subli
Copy link

Ty for the update.
Just update my lambdas, no issues !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants