Netlify functions that use aws-sdk stopped working

Hi there,

As of two days ago, all Netlify functions that use aws-sdk stopped working with the error: Runtime.ImportModuleError: Error: Cannot find module ‘aws-sdk’

Before that, the website(s) were working fine and rolling back to an older deploy fixes the issue for the moment. Also, building the website locally and pushing it up via Netlify CLI works as expected.

I’m using a monorepo and two independent websites (based on GatsbyJS and NextJS) show the same error. The dependency “aws-sdk” is installed in the root package.json for each web app (no separate functions package.json).

What I tried so far:

  • Roll back aws-sdk to a version that is younger than 2 days ago (and remove the carrot)
  • Add the following to the netlify.toml file:
  external_node_modules = ["aws-sdk"]
  • Install aws-sdk as a monorepo dependency

Affected sites with examples:

The console will show the error message.
The console will show an “Internal server error” error but you can see the actual aws-sdk error in the function logs.

Let me know if you need anything else. Thanks!

I expirience the same: Runtime.ImportModuleError - Error: Cannot find module ‘aws-sdk’

Can you share a minimal reproduction? I can’t reproduce it:, repo: GitHub - Hrishikesh-K/f-92710

I’m having the same issue. The function has been working fine for the last few months, but I’m now getting the same error in the last week.

Works fine locally, but fails on preview deploys and production.

Runtime.ImportModuleError - Error: Cannot find module 'aws-sdk'
Require stack: - /var/task/server/gateways/paypal/aws.js - /var/task/server/gateways/paypal/getDonationData.js -
/var/task/server/reporter.js -
/var/task/server/index.js -
/var/task/netlify/functions/donation-reporter.js -
/var/task/donation-reporter.js -

Can you share a minimal reproduction? I can’t reproduce it

Unfortunately, I also wasn’t able to reproduce it with a minimal function build, it’s a weird one.

We also ran into this same issue. Was not able to figure out why, but we were able to work around it by upgrading to AWS client v3 (@aws-sdk/*).

I assume there’s something magical going on with aws-sdk particularly in the Netlify build system that’s breaking it.


Thanks @teropa, I can confirm that upgrading to @aws-sdk v3 fixed the issue!

thanks for confirming!

This also solved the issue for me. Thanks @teropa

Just flagging that we are running into this as well. So odd, const AWS = require(‘aws-sdk’); is throwing an error in some functions but resolving properly in others. Unfortunate, I guess we’ll have to upgrade to v3 as well.