Home > Software engineering >  Lambda function cant load AWS sdk after switching from 12.x to 18.x
Lambda function cant load AWS sdk after switching from 12.x to 18.x

Time:12-01

I upgraded my Lambda function from node12.x to node18.x

The code worked perfectly fine on 12.x, after switching to 18.x, I can no longer include the AWS sdk:

I used to include it by simply typing:

var AWS = require('aws-sdk');

I now get this error

"Error: Cannot find module 'aws-sdk'

I think if I can just get the AWS sdk to load properly the function should be fine, any ideas?

Thanks

CodePudding user response:

The Node.js 18 Lambda runtime is preloaded with the AWS SDK for JS v3.

The earlier runtimes have the SDK v2.

Of course you can still use the SDK v2 with the Node.js 18 runtime. You just need to package the clients as dependencies with your Lambda code.

  • Related