Install the AWS SDK for your Node.js runtime version:
Node.js 16 and earlier (AWS SDK version 2)
To install the latest version of the AWS SDK version 2, use an Amazon Linux 2 compatible instance to run the following command:
npm install aws-sdk
For more information, see Tutorial: Setting up Node.js on an Amazon EC2 instance.
Note: It's a best practice to use an Amazon Linux 2 environment when you develop Lambda resources.
-or-
If you use a Windows or macOS OS for development, then use Docker to run the following command:
docker run --entrypoint "" -v "$PWD":/var/task "public.ecr.aws/lambda/nodejs:<version>" /bin/sh -c "npm install aws-sdk; exit"
Note: Before you run the command, make sure that you're using the most recent version of Docker on the Docker website.
Node.js 18 and later (AWS SDK version 3)
See Installing the SDK for JavaScript.
If you import an AWS SDK command that doesn't exist in the SDK version that's embedded in Lambda, then you might receive the following error:
"Runtime.UserCodeSyntaxError "Named export not found" The requested module is a CommonJS module"
In this case, install the specific package so that you can use it within your function. For example, you use the following import statement:
import {DeleteQueueCommand} from "@aws-sdk/client-connect";
In this case, install the updated client so that you can use the specific package within your function.
For example, you use the following import statement in a Lambda function with Node.js version 18 or later:
import {DeleteQueueCommand} from "@aws-sdk/client-connect";
If this package isn’t in your current AWS SDK version, then you receive the following error in your logs:
""errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Named export 'DeleteQueueCommand' not found. The requested module '@aws-sdk/client-connect' is a CommonJS module, which may not support all module.exports as named exports.\nCommonJS modules can always be imported via the default export, for example using:\n\nimport pkg from '@aws-sdk/client-connect';\nconst {DeleteQueueCommand} = pkg;\n","
To include the DeleteQueueCommand package and resolve this error, install the newest version of the client:
npm install @aws-sdk/client-connect