I'm working on an AWS Lambda function that connects to my database, collects metrics, and logs them to a CloudWatch log stream. I already have other public Lambdas writing to the same log group, and I want to centralize the logs for better diagnostics.
Initially, my Lambda was running in a private subnet, which required VPC endpoints to access Parameter Store and CloudWatch Logs. However, these endpoints are quite costly, so I moved the Lambda to a public subnet.
Now, my Lambda is timing out when trying to access Parameter Store, even though it should have internet access. I'm also facing a timeout when it tries to write to the CloudWatch log group. I can see console outputs in the log group for the Lambda, which suggests it's logging there correctly.
Is there a difference in accessing the Lambda's own log group versus other log groups within the same account? I've made sure the Lambda has permissions to write to the log group, but it's behaving inconsistently. Any insights on why this might be happening would be appreciated!
3 Answers
To connect to services, you could try utilizing an IPv6 Egress-only Gateway. Many AWS services are becoming more accessible via IPv6, so it's worth checking if that could resolve your issue.
You might consider using a VPC Endpoint for CloudWatch Logs, but keep in mind that Lambdas in a VPC can’t directly connect to public endpoints unless you set up some form of NAT. Without a public IP, your Lambda can't go out to the internet at all. Once the traffic hits the VPC border, your private IP won't work for internet access.
For your timeout with Parameter Store, be aware that your Lambda, even when in a public subnet, isn't actually granted a public IP unless specifically configured. You'll definitely need a NAT Gateway or a NAT instance for proper internet connectivity.
As for CloudWatch Logs, the logging is handled on the AWS service side. The Lambda function doesn't route its log data through your VPC, which is why you can see outputs for the Lambda in its own log group but are having trouble with other groups.

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