I've got a Lambda function that handles around 200,000 invocations daily from SQS, and it runs on Node.js. I'm using Glide to connect to Elasticache Serverless v2 (valkey), but I'm experiencing about 30 connection timeouts each day. These timeouts are infrequent compared to the total requests, and I'm trying to figure out the cause. My Lambda is set up in a VPC, spanning two availability zones, with a NAT gateway in place. I've configured a 2-second connection timeout and a 5-second command execution timeout. The error I keep seeing in Sentry is:
ClosingError
Connection error: Cluster(Failed to create initial connections - IoError: Failed to refresh both connections - IoError: Node: "[redacted].serverless.use1.cache.amazonaws.com:6379" received errors: `timed out`, `timed out`)
Any insights would be appreciated!
3 Answers
The errors could be related to network I/O problems. It might be something to look into on your infrastructure side.
Have you considered reusing your connections? Lambda can reuse invocation space, so it's a good idea to check if you have an existing open connection before trying to create a new one.
An I/O error often points to possible hardware issues. Just a theory, but could be worth investigating further!

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically