lambda-api: AWS Lambda with Node 18.x and SDK v3 throws errors
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 16 (3 by maintainers)
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 🙏
PR: https://github.com/jeremydaly/lambda-api/pull/216
@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 ESMTy for the update. Just update my lambdas, no issues !
Thanks for the update. It is working fine with Node 18
Amazing! I will give it a try next week. Thanks in advance for your hard work!
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! ❤️
No, will review it asap 😃