DEV Community

Cover image for Setting a Static IP for AWS Lambda (or any AWS instance)

Setting a Static IP for AWS Lambda (or any AWS instance)

Alex Damiani
A Python enthusiast, dabbling in other stuff when I can.
・2 min read


Youtube video explanation, GitHub repo

What's so important about a static IP?

Having a static outgoing IP for your AWS Lambda function (or any AWS instance) is a common use-case when the third-party you're trying to access data from imposes a restriction that they only accept requests from whitelisted IP addresses. By default, Lambda does not assign a static outgoing IP address and you can't simply assign an AWS elastic IP address to the Lambda function as you could for an AWS EC2 instance.

Setting a static IP for Lambda isn't so simple...

For Lambda, the process is a little more complex. You must:

  1. Create an AWS Virtual Private Cloud (VPC)
  2. Create public and private subnets within the VPC
  3. Place your Lambda function in the private subnet, and a NAT gateway in the public subnet
  4. The NAT gateway is assigned the static Elastic IP, which Lambda routes traffic too
  5. The NAT gateway then routes traffic to the Internet gateway which passes that traffic onto our third-party endpoint with a static outgoing IP


Alt Text


Alt Text

I walk through everything in my YouTube series, explaining how to create it manually and then automatically with AWS Cloudformation, explaining each component and the values chosen along the way.

How you can help me

If you find the video helpful you can greatly help me by doing one or all of the following:

Discussion (0)