I am new to working with lambda functions. I have a very simple problem I think. I have a lambda function that collects metrics from an external server and then sends them to Cloudwatch.
Everything works fine until I add a VPC to the lambda function, the metrics from the external server are collected correctly but when it gets to the part of putting the metrics (cw.put_metric_data(...)
) it immediately throws me Timeout
.
What can I be doing wrong?
Fixed:
A lambda function without VPC configuration has free access to the public Internet and some AWS services by default. However, when you configure a VPC, you only have access to the resources within that VPC. To mitigate this problem you can setup a VPC endpoint to enable private communications between your VPC and supported AWS services as explained in the VPC developer docs. Specifically for CloudWatch, the service to choose is com.amazonaws.Region.logs
as stated in the CloudWatch documentation.