-
Notifications
You must be signed in to change notification settings - Fork 824
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
Getting Error: Cannot find module 'aws-sdk' in Lambda since switching to node18 #13278
Comments
Hey @PeteDuncanson 👋 thanks for raising this! With support for Node 18 in Lambda AWS SDK v2 was removed from the base image in favor of AWS SDK v3. As you have found downgrading to Node 16 will resolve this, however you can also install |
I am also curious about the issue you're experiencing with diagnose 👀 do you get an error and/or stack trace if you run |
Hey @josefaidt my friend. I'll try that. So with v2 installed by default does that mean I don't have to import it? Im not importing anything from aws in my functions but maybe there's something global that im using somewhere and that's the issue. That would make sense. I'll check tomorrow. For your last comment there's an issue for it. Would love to get it sorted to help with stuff like this so feel free to cast an eye over it #10980 |
Hey @PeteDuncanson it will be installed by default but you would need to import/require it. Is this log coming from one of your project's functions or perhaps one of the generated functions in the auth template, etc.? |
Got the same issue when upgrade to nodejs18.x, since nodejs12.x is deprecated. it related to the error #3173, but that ticket has been closed. Not sure nodejs16.x, will take a try. But not sure what can be done if nodejs16.x is deprecated later. updateswork with nodejs16.x |
I am having this problem with the AdminQueries created by amplify update auth. Works fine when I downgrade the runtime to "nodejs16.x" but when I upgrade to the recommended "nodejs20.x" or even "nodejs18.x" it doesn't. Not sure how to fix this since I am not hosting my front end (nextjs) on AWS. |
I'm never ashamed to be that one person that puts their hand up and says they don't know something. If I'm feeling confused others must be to. Could I ask for a hand holding walk through from someone on the AWS Team of how this issue should be found and fixed as currently I'm still unsure how to make it go away (other than leaving it running on Node 16). What commands do we need to run? Give me a walk through like I'm an idiot so I can understand more and others coming behind can follow along without having to be the one to put their hand up :) |
Hey @PeteDuncanson 👋 I went through the motions of upgrading an "older" project and captured the following notes:
This is assuming the Function source code is not being migrated to use AWS SDK v3, which is now baked into the Node.js 18.x runtime for Lambda. Let me know if this helps! |
I had already migrated the rest of my project to the v3 SDK so what I ended up doing was to copy the Admin Queries source code from a new project that was generated with the Node.js 18x runtime to my older project. Since I hadn't customized the actual generated Admin Queries code, this worked perfectly. This code can be found in the project folders under your-project/amplify/backend/function/your-admin-queries-name/src/ |
Closing the issue due to inactivity. Do reach out to us if you are still experiencing this issue |
|
How do you do this update for UserPoolClientLambda? |
How did you install the Amplify CLI?
yarn
If applicable, what version of Node.js are you using?
node18 in my Lambda
Amplify CLI Version
12.5.1
What operating system are you using?
Windows
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
I've recently updated all my Lambdas to run on node18 instead of node16 following the manual steps in #10894
However to get it running again I've manually switched my Lambda back to node16.
Describe the bug
When running my Lambda in production I get the following error:
Error: Cannot find module 'aws-sdk'
From what I've read (https://aws.amazon.com/blogs/compute/node-js-18-x-runtime-now-available-in-aws-lambda/) this is to be expected when switching to node18 as aws-sdk isn't bundled up for node18 as it was for node16.
Trouble is I'm not importing aws-sdk in my Lambda so I'm not sure where this error is coming from?
For now I've manually reverted back to node16 to get the Lambda running.
Expected behavior
If I'm not importing aws-sdk I'm not sure why its complaining?
Its a Lambda created with Amplify CLI that I'm using in my schema via the @function directive. Its talking to GraphQL via axios but thats about it.
Reproduction steps
Create a lambda.
Edited the cloudformation templates ala #10894 (comment) but for node18
Push up
Run the Lambda
Now this Lambda was created on an older version of the CLI so I'm not sure if this is a fixed thing now or not.
Project Identifier
This never works for me :(
Log output
Additional information
No response
Before submitting, please confirm:
The text was updated successfully, but these errors were encountered: