Does All AWS SDK V3 Clients keep persistent connections?

0

I'm currently developing Hello,

I am developing an AWS Lambda function in Typescript and aiming to optimize performance by initializing AWS SDK v3 clients before the Lambda execution starts. I want to confirm whether all AWS SDK v3 clients (e.g., S3, Cognito, SNS, etc.) maintain a persistent connection (e.g., keep-alive, connection pooling) by default when instantiated outside the Lambda handler.

If they do, does this behavior apply across all AWS services in SDK v3, or are there exceptions? Additionally, are there specific configurations or best practices to ensure persistent connections are reused across multiple Lambda invocations within the same execution environment?

Thanks in advance for your help!

2 Answers
2
Accepted Answer

AWS SDK v3 for JavaScript/TypeScript does indeed maintain persistent connections by default for most services. This is achieved through connection pooling and keep-alive mechanisms. However, it's important to note that the exact behavior can vary slightly depending on the specific service and the underlying protocol used.

While the general principle of connection reuse applies to most AWS services in SDK v3, there can be some variations:

HTTP/HTTPS Services: Most AWS services that use HTTP/HTTPS (like S3, SNS, SQS, DynamoDB, etc.) benefit from connection reuse.
WebSocket Services: Some services that use WebSocket connections (like IoT) may have different connection management.
Specific Service Behaviors: Some services might have unique connection handling due to their nature or security requirements.

https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html

AWS
answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago
  • Where can I find out or how can know If a certain service supports connection pooling or keep-alive mechanisms?

1

One thing not covered in the answer above:

Persistent connections are not used across different Lambda invocations - each invocation is a separate execution environment and creates/maintains its own connections to anything on the network (AWS services included).

profile pictureAWS
EXPERT
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions