Home > database >  Understanding NAT Gateway traffic flow for Lambda for cost purposes
Understanding NAT Gateway traffic flow for Lambda for cost purposes

Time:03-18

My current architecture includes a Lambda function in a private subnet that basically needs to access the internet to fetch weather data. I have set up a NAT gateway to allow the Lambda function to access the internet.

What I am confused about is what counts for "Data processed per GB" for the NAT gateway? For example, the HTTP request from the lambda payload is of size 1Gb but the response from the public website is of size 200Gb. So would the total data be processed by 1Gb or would it be 201Gb?

P.S. Payload size for both request and response is hypothetical to better represent the scenario

CodePudding user response:

Every GB of data that goes through the NAT, whether in or out, will be charged at 4.5 cents (in the US regions; check pricing pages for elsewhere).

So in your example, you will be charged for 201 GB (1 out, 200 in).

That assumes that you have a NAT running in each availability zone where you are consuming/producing data. If you run a single NAT (a bad idea), you'll also pay for cross-AZ data transfer, at $0.02 per GB.

If you are retrieving a large amount of data, I recommend running your Lambda outside the VPC. You won't be charged for the retrieved data, nor will you be charged for writing that data to the AWS services described here.

  • Related