Run AWS Lambda function with Static IP address
Posted By : Ankit Uniyal | 26-Dec-2017
In this blog, we will discuss about how we can run our AWS Lambda function with a single static IP address.
I have worked on some of the smaller server-less micro services on AWS Lambda which is used for stateless web applications in cloud.AWS Lambda provides us a feature where we can run our code without worrying about the Infrastructure and deployment.AWS Lambda runs in a container which uses set of IP addresses to execute, but on every execution AWS Lambda use different IP address for execution.
Now, the problem will only come when we need to deploy or send data to a server but the server will accept request from a particular IP address only.In that case, we want our AWS Lambda function to use same IP address on every execution.
Here is the solution, we can execute our AWS Lambda function inside a VPC which is Virtual Private Connection as AWS Lambda supports the execution of our code in a VPC enabled environment.
We will create a NAT(Network Address Translator) gateway and assign fix IP address and thus all outbound traffic from our lambda function will exit from NAT.
Below are the things which we need to follow to execute our lambda function inside a VPC :
1.Create a new VPC under VPC console so that your lambda code will run inside it.
2.Create new Internet Gateway which use to communicate with the Internet within your VPC.
3.Create a Public Subnet and also add a new route which then routes to Internet gateway from 0.0.0.0/0.
4.Also, create new Elastic IP addresses along with new NAT Gateway and then assign it to Public Subnet and NAT gateway.
5.Now, create a Private Subnet and also add new route which then routes to my NAT gateway from 0.0.0.0/0.
Now, we need to create a Lambda function and assign the created VPC to the Lambda along with the security groups.
We can test the same by using any public url or google.com to test the Internet connection.We can done this by using "request" npm module in NodeJS.
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ankit Uniyal
Ankit has knowledge in Javascript, NodeJS, AngularJS and MongoDB also have experience in using AWS Services.