Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'@smithy/node-http-handler' not included in lambda Node.js 20.x runtime #6169

Closed
3 tasks done
mellster2012 opened this issue Jun 5, 2024 · 6 comments
Closed
3 tasks done
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue workaround-available This issue has a work around available.

Comments

@mellster2012
Copy link

mellster2012 commented Jun 5, 2024

Checkboxes for prior research

Describe the bug

The documentation at https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#request-handler-requesthandler says to use '@smithy/node-http-handler' but the lambda fails with "errorMessage": "Cannot find package '@smithy/node-http-handler' imported from /var/task/index.mjs", "code": "ERR_MODULE_NOT_FOUND", regardless of whether the module is specified as a dependency in package.json or not.

SDK version number

@aws-sdk/client-s3 3.4x and 3.5x

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node.js v20

Reproduction Steps

import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { NodeHttpHandler } from '@smithy/node-http-handler';

const s3 = new S3Client({
  requestHandler: new NodeHttpHandler({
    httpsAgent: new https.Agent({
      maxSockets: 150,
    }),
  })
});
[...]

Observed Behavior

2024-06-05T19:28:48.275Z	undefined	ERROR	Uncaught Exception 	
{
    "errorType": "Error",
    "errorMessage": "Cannot find package '@smithy/node-http-handler' imported from /var/task/index.mjs",
    "code": "ERR_MODULE_NOT_FOUND",
    "stack": [
        "Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@smithy/node-http-handler' imported from /var/task/index.mjs",
        "    at packageResolve (node:internal/modules/esm/resolve:858:9)",
        "    at moduleResolve (node:internal/modules/esm/resolve:931:18)",
        "    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:1161:14)",
        "    at defaultResolve (node:internal/modules/esm/resolve:1204:79)",
        "    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)",
        "    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)",
        "    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)",
        "    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)",
        "    at link (node:internal/modules/esm/module_job:86:36)"
    ]
}

Expected Behavior

Module should be found.

Possible Solution

Workaround is to use
import { NodeHttpHandler } from '@aws-sdk/node-http-handler';
instead.

Additional Information/Context

No response

@mellster2012 mellster2012 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 5, 2024
@aBurmeseDev
Copy link
Member

Hi @mellster2012 - thanks for reaching out.

Can you verify if you've installed smithy/node-http-handler in your packages? @aws-sdk/node-http-handler has been deprecated and some packages from @aws/sdk* were moved over to @smithy/*. Refer to this comment.

Smithy is a language for defining services and SDKs. It is open source software maintained by AWS.

Smithy is used to generate both the AWS SDK for JavaScript v3, and other similar SDKs not necessarily related to AWS. Therefore, we decided to detach the AWS SDK namespace from core components used outside of AWS, such as the generic node http handler.

@aBurmeseDev aBurmeseDev self-assigned this Jun 10, 2024
@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jun 10, 2024
@aBurmeseDev
Copy link
Member

aBurmeseDev commented Jun 13, 2024

@mellster2012 - this's reproducible when running code in Lambda provided SDK and we were able to confirm it.

Please use the shortened syntax to configure requestHandler until fix is released. (ref: P135205927)

// Example: short form requestHandler configuration.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";

const client = new DynamoDBClient({
  requestHandler: {
    requestTimeout: 3_000,
    httpsAgent: { maxSockets: 25 },
  },
});

@aBurmeseDev aBurmeseDev added p2 This is a standard priority issue queued This issues is on the AWS team's backlog and removed response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p3 This is a minor priority issue labels Jun 13, 2024
@kuhe
Copy link
Contributor

kuhe commented Jun 13, 2024

The bundled SDK is provided as a convenience for developers building simpler functions or using the Lambda console for development

https://docs.aws.amazon.com/lambda/latest/operatorguide/sdks-functions.html

The AWS Lambda provided AWS SDK for JavaScript is only updated periodically, and may be missing features that the most recent AWS SDK version contains. When it does update, it is done automatically without a way to opt-out.

Therefore, in addition to the workaround shown above, for stability in production usage you should provide your own AWS SDK version as part of your uploaded application.

@kuhe kuhe added workaround-available This issue has a work around available. and removed queued This issues is on the AWS team's backlog labels Jun 13, 2024
@mellster2012
Copy link
Author

The bundled SDK is provided as a convenience for developers building simpler functions or using the Lambda console for development

https://docs.aws.amazon.com/lambda/latest/operatorguide/sdks-functions.html

The AWS Lambda provided AWS SDK for JavaScript is only updated periodically, and may be missing features that the most recent AWS SDK version contains. When it does update, it is done automatically without a way to opt-out.

Therefore, in addition to the workaround shown above, for stability in production usage you should provide your own AWS SDK version as part of your uploaded application.

Providing the missing/additional dependency explicitly in package.json doesn't work either, though. Do you have to add an option to bundle your own AWS, such as mentioned here: aws/aws-cdk#25492 ? And is there a way to instruct it to take the currently provided AWS SDK at runtime and add a few extra dependencies found in package.json, or do you have to either provide your (entire) own custom AWS SDK or nothing?

@aBurmeseDev
Copy link
Member

Providing the missing/additional dependency explicitly in package.json doesn't work either, though

Can you elaborate more on that or share what you did with repro code? I've confirmed the workaround mentioned above with providing @smithy/node-http-handler dependency works. Let us know if we're missing something.

@aBurmeseDev aBurmeseDev added the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jun 13, 2024
@mellster2012
Copy link
Author

Providing the missing/additional dependency explicitly in package.json doesn't work either, though

Can you elaborate more on that or share what you did with repro code? I've confirmed the workaround mentioned above with providing @smithy/node-http-handler dependency works. Let us know if we're missing something.

You are right, I missed that Code.fromAsset does not automatically bundle additional dependencies outside of the lambda handler folder. We can keep using @aws-sdk/node-http-handler (which is working fine) and wait until @smithy/node-http-handler is included or switch the build process for the affected lambda and include @smithy/node-http-handler as a dependency. Thank you!

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jun 15, 2024
@kuhe kuhe closed this as completed Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue workaround-available This issue has a work around available.
Projects
None yet
Development

No branches or pull requests

3 participants