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 個月前檢視次數 6364 次
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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南