Node 18 tries to import aws-sdk

0

I've recently upgrade lamdba to node 18 and some of the functions seem to be throwing the following error. I am no longer using the 'aws-sdk' but the '@aws-sdk/client' v3 versions

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'aws-sdk'\nRequire stack:\n- /var/task/api/v1/onboarding/registerEmail/handler.js\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'aws-sdk'",
        "Require stack:",
        "- /var/task/api/v1/onboarding/registerEmail/handler.js",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:1061:17)",
        "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1093:21)",
        "    at async start (file:///var/runtime/index.mjs:1256:23)",
        "    at async file:///var/runtime/index.mjs:1262:1"
    ]
}

Sven
已提问 8 个月前6330 查看次数
2 回答
0
已接受的回答

Turns out there was a layer attacked to some of the functions which tried to use the 'aws-sdk'

Sven
已回答 8 个月前
0

If your existing Lambda functions are using the included SDK v2, then you must update your function code to use the SDK v3 when upgrading to the Node.js 18 runtime. This is the recommended approach when upgrading existing functions to Node.js 18. Alternatively, you can use the Node.js 18 runtime without updating your existing code if you deploy the SDK v2 together with your function code.

Reference :

  1. https://aws.amazon.com/blogs/compute/node-js-18-x-runtime-now-available-in-aws-lambda/
  2. https://aws.amazon.com/blogs/developer/why-and-how-you-should-use-aws-sdk-for-javascript-v3-on-node-js-18/
profile pictureAWS
专家
已回答 8 个月前
  • As I mentioned, the functions are no longer use the SDK v2.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则