3

I've the following scenario:

I have an external API what I need to call from a Lambda function. The external API has some restrictions:

  • Require an API key what stick to the caller's IP address
  • Only 1:1 (IP : API key) mappings allowed

Our environment:

  • For stake of redundancy we have 3 private subnets in 3 availability zone connected to the internet with 3 NAT gateways.
  • If I put my lambda function into those 3 subnets, it call out randomly with the 3 EIPs of the NAT gateway.
  • So I need to lookup for the current subnet inside the lambda. From this information I can use the API key of the designated EIP for the external API request.

So my question:

How can I determine, in which subnet my lambda functions is currently running in?

As I checked unfortunately the context doesn't contain this information (according to the documentation) This doesn't answer the question: Find subnet of a lambda running in a vpc As it give back the configuration what contains all of the subnets and not the current one

SUF
  • 31
  • 2
  • FYI, I took a look at the `context` and couldn't find anything relevant. If the linked answer doesn't help, then you probably can't obtain the desired information. However, somebody else might have a suggestion. – John Rotenstein Feb 06 '22 at 07:56
  • @JohnRotenstein The linked answer give back the configuration what contains all of the subnets, and not the specific one, where I execute the lambda. Currently the only thing I can think of to ask some external provider like https://ipfy.org for my external IP but I would rather avoid adding more external services into the picture. – SUF Feb 06 '22 at 08:01
  • 1
    For other readers... We were referring to [Find subnet of a lambda running in a vpc - Stack Overflow](https://stackoverflow.com/questions/60870477/find-subnet-of-a-lambda-running-in-a-vpc), which does not appear to be a suitable answer. – John Rotenstein Feb 06 '22 at 08:06
  • What about some basic networking code in whatever programming language you are using to get the Lambda function's IP address? That would give you the internal VPC IP address. You could then easily map that IP address to the CIDR block of one of the VPC subnets. – Mark B Feb 06 '22 at 14:56

0 Answers0