AWS Lambda sending HTTP request
<p>This is likely a question with an easy answer, but i can't seem to figure it out.</p>

<p>Background: I have a python Lambda function to pick up changes in a DB, then using HTTP post the changes in json to a URL. I'm using urllib2 sort of like this:</p>

<pre><code># this runs inside a loop, in reality my error handling is much better
request = urllib2.Request(url)
request.add_header('Content-type', 'application/json')
try:
    response = urllib2.urlopen(request, json_message)
except:
    response = "Failed!"
</code></pre>

<p>It seems from the logs either the call to send the messages is skipped entirely, or times-out while waiting for a response. </p>

<p>Is there a permission setting I'm missing, the outbound rules in AWS appear to be right. [Edit] - The VPC applied to this lambda does have internet access, and the security groups applied appear to allow internet access. [/Edit]</p>

<p>I've tested the code locally (connected to the same data source) and it works flawlessly. </p>

<p>It appears the other questions related to posting from a lambda is related to node.js, and usually because the url is wrong. In this case, I'm using a requestb.in url, that i know is working as it works when running locally.</p>

<p>If you've deployed your Lambda function inside your VPC, it does not obtain a public IP address, even if it's deployed into a subnet with a route to an Internet Gateway.  It only obtains a private IP address, and thus can not communicate to the public Internet by itself.</p>

<p>To communicate to the public Internet, Lambda functions deployed inside your VPC need to be done so in a private subnet which has a <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Route_Tables.html#route-tables-nat" rel="nofollow">route</a> to either a <a href="https://aws.amazon.com/blogs/aws/new-managed-nat-network-address-translation-gateway-for-aws/" rel="nofollow">NAT Gateway</a> or a self-managed <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_NAT_Instance.html" rel="nofollow">NAT instance</a>.</p>

python python-2.7 amazon-web-services aws-lambda