Since Node.js 18 the AWS-SDK library is not available in the Node.js 18 runtime anymore. You can use the aws-sdk-v3 module instead. This module is not compatible with the old one, so you have to change your code.
But there is another way to use the old AWS-SDK package by using AWS Lambda Layers without changing your build steps. This is a great way to use the old AWS-SDK package without changing your code.
Within Serverless you can create AWS Lambda Layers by using the layers property. You can add the aws-sdk package to the layer and use it in your Lambda function.
1service: my-service
2provider:
3 name: aws
4 runtime: nodejs18.x
5layers:
6 aws-sdk:
7 path: layers/aws-sdk
8 compatibleRuntimes:
9 - nodejs18.x
The layers/aws-sdk folder contains the nodejs folder. In this folder you can add the package.json file with the aws-sdk package.
1{
2 "dependencies": {
3 "aws-sdk": "^2.1032.0"
4 }
5}

