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

Slow import time for clients #5382

Closed
3 tasks done
mk0sojo opened this issue Oct 18, 2023 · 4 comments
Closed
3 tasks done

Slow import time for clients #5382

mk0sojo opened this issue Oct 18, 2023 · 4 comments
Assignees
Labels
bug This issue is a bug.

Comments

@mk0sojo
Copy link

mk0sojo commented Oct 18, 2023

Checkboxes for prior research

Describe the bug

Currently upgrading from AWS SDK v2 to AWS SDK v3 and importing @aws-sdk/client-xxx is slower than I would expect and is causing very slow cold starts (close to 1 second).

SDK version number

@aws-sdk/client-dynamodb@latest, @aws-sdk/client-s3, @aws-sdk/client-ssm

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node 18 lambda

Reproduction Steps

  1. In the AWS console create a new Node 18 lambda. Set the memory to 1024 MB
  2. It is pre populated with the following code:
export const handler = async (event) => {
  // TODO implement
  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};
  1. Test run the code, this returns something like this:
Response
{
  "statusCode": 200,
  "body": "\"Hello from Lambda!\""
}

Function Logs
START RequestId: 12248941-44db-4e8c-93fa-458c0080ad45 Version: $LATEST
END RequestId: 12248941-44db-4e8c-93fa-458c0080ad45
REPORT RequestId: 12248941-44db-4e8c-93fa-458c0080ad45	Duration: 2.66 ms	Billed Duration: 3 ms	Memory Size: 1024 MB	Max Memory Used: 67 MB	Init Duration: 172.79 ms

Init duration (cold start) here is 172.79 ms which is expected.

  1. Now add a few imports to the top of the file so it looks like this:
import { DynamoDBClient, GetItemCommand } from "@aws-sdk/client-dynamodb"
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm";

export const handler = async (event) => {
  // TODO implement
  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};
  1. Deploy and test. This will return something like this:
Response
{
  "statusCode": 200,
  "body": "\"Hello from Lambda!\""
}

Function Logs
START RequestId: fa753048-9567-4836-b9e7-278df1a9767f Version: $LATEST
END RequestId: fa753048-9567-4836-b9e7-278df1a9767f
REPORT RequestId: fa753048-9567-4836-b9e7-278df1a9767f	Duration: 2.56 ms	Billed Duration: 3 ms	Memory Size: 1024 MB	Max Memory Used: 115 MB	Init Duration: 917.74 ms

Request ID
fa753048-9567-4836-b9e7-278df1a9767f

The cold start time is now 917.74 ms. This seems quite large (and this is before creating any clients (and definately more than AWS SDK v2). Is this expected?

Observed Behavior

Slow cold start time when importing AWS SDK clients.

Expected Behavior

A bit faster?

Possible Solution

No response

Additional Information/Context

No response

@mk0sojo mk0sojo added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 18, 2023
@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Oct 18, 2023
@kuhe
Copy link
Contributor

kuhe commented Oct 19, 2023

We recommend creating a bundled application if cold start times are a concern.

https://aws.amazon.com/blogs/developer/reduce-lambda-cold-start-times-migrate-to-aws-sdk-for-javascript-v3/

@mk0sojo
Copy link
Author

mk0sojo commented Oct 20, 2023

When I bundle it it takes around 450 ms for a cold start which is similar to v2 I think.

@yenfryherrerafeliz yenfryherrerafeliz removed the needs-triage This issue or PR still needs to be triaged. label Oct 20, 2023
@yenfryherrerafeliz
Copy link
Contributor

@mk0sojo I am glad to hear that bundling the SDK helped you in reducing the cold start times. It is actually what we recommend as @kuhe said. I am going to resolve this issue now, but please if you have anything else that we can help you with, feel free of opening a new issue.

Thanks!

Copy link

github-actions bot commented Nov 4, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants