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.
For Lambda, the process is a little more complex. You must:
- Create an AWS Virtual Private Cloud (VPC)
- Create public and private subnets within the VPC
- Place your Lambda function in the private subnet, and a NAT gateway in the public subnet
- The NAT gateway is assigned the static Elastic IP, which Lambda routes traffic too
- The NAT gateway then routes traffic to the Internet gateway which passes that traffic onto our third-party endpoint with a static outgoing IP
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.
If you find the video helpful you can greatly help me by doing one or all of the following:
- supporting me on Patreon
- subscribing to my YouTube channel
- liking and/or commenting on the video
- sharing the video or channel on any platform (reddit, twitter, discord, etc.)
- starring the GitHub repo
- following me on GitHub
Any questions or requests, just leave a comment.
Top comments (0)