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
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.
The v2 SDK's aws-sdk package (preloaded on the 14.x, 16.x Lambda Node.js runtimes) contains every client. The v3 service clients (preloaded on 18.x) are modularised in separate @aws-sdk/client-[something] packages. Here's a v3 sample import for getting an S3 object:
// v3
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"
See the Getting Started guide in the SDK v3 docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With