Python request in AWS Lambda timing out

I'm trying to make a http request from my AWS Lambda but it times out.

My code looks similiar to this:

import requests

def lambda_handler(event, context):
    print('Im making the request')
    request.get('http://www.google.com')
    print('I recieved the response')

But when I test this, I get a timeout.

The output is

Im making the request
END RequestId: id
REPORT RequestId: id    Duration: 15003.25 ms   Billed Duration: 15000 ms   Memory Size: 128 MB Max Memory Used: 18 MB  
2016-04-08T20:33:49.951Z id Task timed out after 15.00 seconds

So I know the issue isn't it not finding the request package, and it's running my python code. I just figure out why it times out on that request.

Answers 1

  • I encounter same timeout problem, the reason is below.

    AWS document:

    When you add VPC configuration to a Lambda function, it can only access resources in that VPC. If a Lambda function needs to access both VPC resources and the public Internet, the VPC needs to have a Network Address Translation (NAT) instance inside the VPC.

    Maybe there are some error when you setting your VPC. I advice you can follow this blog to build NAT.


Related Articles