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
asked 8 months ago5878 views
2 Answers
0
Accepted Answer

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

Sven
answered 7 months ago
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
EXPERT
answered 8 months ago
  • As I mentioned, the functions are no longer use the SDK v2.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions