Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why AWS lambda functions In a VPC sometimes timeout and sometimes work fine?

I have some lambda functions in a VPC, some of them need Internet to work so I added a NAT instance (t2.micro) and the problem is that I have some functions sometimes work and sometimes timeout. For example a function that call FB API 80% of the time work and 20% timeout. Another function is using boto3 to create a spot instance 50% of the time timeout and the logs give me.

2018-07-16T06:35:55.909Z 421f98dd-88c2-11e8-913a-63c8d6f276f3 Task timed out after 100.10 seconds

Whenever I redeploy my serverless project I face this problem.

I increased the timeout limit and the memory but I have the same problem I'm sure that there is access to Internet but some of the lambda functions timeout.

What do you think the problem is ? Thanks

like image 527
Bacem Mehri Avatar asked Jul 17 '18 05:07

Bacem Mehri


1 Answers

I've had this where I am using the Lambda in a VPC (and therefor have a NAT Gateway and Internet Gateway in place).

I had inadvertently selected all subnets (including the public one) for the Lambda to run in, whereas it will only have access to the internet from the private subnets.

Deselect the public subnet and save and you should solve your problem.

Here's a link to the knowledgebase article I used - https://aws.amazon.com/premiumsupport/knowledge-center/internet-access-lambda-function/

like image 83
Liam Avatar answered Dec 20 '22 21:12

Liam