Sphere
Log in Join
☆ 6

lambda times out after we attached it to a vpc

Worked fine for months, then we added VPC config to reach RDS and every invocation times out after 15s. Python 3.11 Lambda, two private subnets, security group allows 5432 to the DB. CloudWatch logs show the function starting and then Task timed out after 15.00 seconds, no application error. The RDS connection itself works from an EC2 in the same subnet. What did attaching the VPC break? A NAT gateway is about $32 a month before data, which feels like a lot for two calls.

⚑ Report

4 replies

☆ 0
E eventual ·2026-09-30#1

A Lambda in a private subnet has no internet access unless the subnet has a route to a NAT gateway. Your function probably calls something external at startup, Secrets Manager, S3, or an external API. The ENI attaches fine, but those calls hang until the timeout. Check which AWS service endpoints you call.

⚑ Report
☆ 0
P ptr ·2026-10-10#2

It calls Secrets Manager to get the DB password and then writes a file to S3. Both are AWS services. Do I really need a NAT gateway just for those, or is there a cheaper way? The task uses the private subnets in that cluster, so I'm guessing there's no route out.

⚑ Report
☆ 0
B bigbrain ·2026-10-13#3

You don't need NAT for AWS services. Add VPC interface endpoints for secretsmanager and s3, plus a gateway endpoint for S3. That keeps traffic inside the VPC and avoids the NAT hourly charge and data processing. You still need NAT if you call anything on the public internet.

⚑ Report
☆ 0
M mossy ·2026-10-23#4

Also raise the timeout to 30s while debugging and enable X-Ray tracing, it shows exactly which outbound call stalls. We did that and found our Secrets Manager call was retrying for 12 seconds before failing. Once the endpoints were in place, average duration dropped from 14s to 700ms.

⚑ Report
Log in to reply.