Skip to content

make AWS SDK JS v2 and v3 available with ESM in AWS Lambda #3230

Closed
@shishkin

Description

@shishkin

Describe the bug

Nodejs lambda is not able to find AWS SDK.

Your environment

SDK version number

Tried latest v2 and latest v3 with same effect:
@aws-sdk/client-s3@npm:3.48.0
aws-sdk@npm:2.1062.0

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the browser/Node.js/ReactNative version

Node.js 14 AWS Lambda runtime

Steps to reproduce

Here is the code of the lambda:

// src/lambda.ts
import { S3 } from "aws-sdk";
import { URLSearchParams } from "node:url";
var { REGION, BUCKET_NAME } = process.env;
var s3 = new S3({ region: REGION });
var handler = async (e) => {
  console.debug("Event:", e);
  const { message } = e;
  const greeting = hello(message);
  const s3result = await s3.putObject({
    Bucket: BUCKET_NAME,
    Key: `greetings/hello.txt`,
    Tagging: new URLSearchParams({
      type: "greeting"
    }).toString(),
    ContentType: "text/plain; charset=UTF-8",
    Body: greeting
  }).promise();
  console.debug("S3 result:", s3result);
};
var hello = (message) => `Hello, ${message}!`;
export {
  handler,
  hello
};

Observed behavior

Lambda fails with error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'aws-sdk' imported from /var/task/index.mjs

Expected behavior

Reading the guide, I understand that aws-sdk should be already available on Nodejs runtimes.

Additional context

I'm trying to make use of newly announced ESM support in the Nodejs14 AWS Lambda runtime and make the smallest possible lambda bundle, hence the reason for not bundling AWS SDK.

Metadata

Metadata

Labels

feature-requestNew feature or enhancement. May require GitHub community feedback.p2This is a standard priority issuewontfixWe have determined that we will not resolve the issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions