简体   繁体   中英

AWS Lambda Timeout when Triggered through Cloudwatch

I have a lambda function that makes requests to external API which requires a static IP to whitelist. I have created a VPC with an assigned elastic IP to solve this.

The function works perfectly when testing on the AWS Lambda console but if triggered using EventBridge (CloudWatch Events), it always times out:

2020-10-01T11:12:29.219Z 012df4ee-bb1e-4821-b1a2-6c3396ca760b Task timed out after 720.00 seconds

I thought the issue was the VPC, but considering this works when I manually trigger it I think there may be an issue with how the function is being triggered by cloudwatch.

Has anyone had the problem before?

It is not possible to assign an Elastic IP address to an AWS Lambda function.

Instead:

  • Create an Elastic IP address
  • Create a NAT Gateway or NAT Instance in a public subnet and configure the private subnet(s) to use the NAT Gateway/NAT Instance
  • Associate the Elastic IP address with the NAT Gateway/NAT Instance
  • Configure the Lambda function to connect to a private subnet

The Lambda function will then access the Internet via the NAT Gateway/NAT Instance, using the assigned Elastic IP address.

See: Give Internet Access to a Lambda Function in a VPC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM