How to choose Elastic IP when my aws lambda function execute
Asked Answered
A

3

5

I want to select specific Elastic IP my own when my lambda function executed.

my service has to respond to several situations, and by user's attributes. Could I write code in a lambda function, that can choose specific my own elastic IP?

I had searched for this. but old information says it cannot do. but recently I heard about it is possible by using Network Load Balancer or Application Load Balancer. But I don't know how to use this for the problem.

Alcohol answered 20/4, 2019 at 6:57 Comment(2)
What do you mean by "choose"? Give an exampleKharif
Why do you wish to do this? Most use-cases for people wanting to use multiple public IP addresses is to perform scraping against websites that block too much traffic coming from a given IP address. We do not support or encourage violating a web site's terms and conditions.Dominy
D
22

No. You cannot associate an Elastic IP (EIP) address with an AWS Lambda function.

Well, actually you can, but I wouldn't recommend it. When a Lambda function is associated with a VPC, it connects via an Elastic Network Interface (ENI). It is possible to attach an EIP to an ENI. This also grants access to the Internet if it is attached to a public subnet.

So why avoid it? Because Lambda might create additional ENIs, especially if the Lambda function is frequently invoked and run in parallel. This means it will not have a consistent ENI.

An alternative method is:

  • Attach the AWS Lambda function to a private subnet
  • Put a NAT Gateway in a public subnet
  • Associate an Elastic IP address with the NAT Gateway
  • All traffic from the Lambda function to the Internet will then come from the NAT Gateway's EIP (however, I don't think you can change that EIP)
Dominy answered 20/4, 2019 at 7:49 Comment(1)
Can you provide a link to the free solution? Attaching Elastic IP to Lambda function without using NAT Gateway or NAT instanceOs
N
0

I had a similar question: how do I create a lambda stack that can grab some data from an endpoint on the internet, parse it, and load it into an RDS in a private-isolated subnet inside my VPC on AWS.

I ended up going with 2 lambda functions (one on private subnet, and the other not connected to my VPC), and communicating the parsed data between the two lambdas using an SNS/SQS, because I can open an endpoint on the private-subnet for the SNS/SQS messages to pass through.

I found this answer to be more complete: https://stackoverflow.com/a/74683282

Numerary answered 9/3, 2023 at 19:17 Comment(0)
E
-1

Looking at @John Rotenstein's reply: for small systems, with limited calls to the same lambda adding an EIP to the ENI for a lambda could work - if you put a queue in front of the lambda to handle the requests and limit the concurrency of the lambda to 1. That's cheaper than a NAT Gateway (saves around $30) per month. For larger systems, this may not be an issue and you may need the concurrency to be more than one - in that case the NAT gateway is the only way out.

Epiphysis answered 22/3, 2020 at 21:42 Comment(1)
Can you provide a link to the free solution? Attaching Elastic IP to Lambda function without using NAT Gateway or NAT instanceOs

© 2022 - 2024 — McMap. All rights reserved.