AWS Lambda: How to set up a NAT gateway for a lambda function with VPC access
<p>As per <a href="http://docs.aws.amazon.com/lambda/latest/dg/vpc.html" rel="noreferrer">this document</a>, if I need to access internet resources from my Lambda function with VPC access, I need to set up a NAT gateway. </p>

<p>So I followed <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat-gateway.html" rel="noreferrer">this guide</a> to set up a NAT gateway. However, at the stage when I need to edit the route tables of my subnet to add an entry with destination: 0.0.0.0/0 and target as my NAT gateway's id, I got an error that </p>

<pre><code>An entry with this destination already exists
</code></pre>

<p>I checked and noticed that for that existing entry, the target was an internet gateway for my VPC. If I replace that entry with the NAT gateway id, I cannot access any of the EC2 instances in that VPC through SSH from the outside world. How can I achieve a solution where all the EC2 instances in this VPC:</p>

<ul>
<li>Are accessible only via SSH and the rest of the traffic is blocked</li>
<li>Are able to completely access other EC2 instances in the same VPC</li>
<li>Lambda function having access to this VPC can access outside resources like SQS and Kinesis.</li>
</ul>