4
votes

I hava a lambda function that runs from a VPC. We have three avalability zones configured for HA. I would like to know from which Availability Zone is each Lambda invocation running.

My lamdba uses python 3.7 as runtime

I tried this

import socket    
hostname = socket.gethostname()    
IPAddr = socket.gethostbyname(hostname)    
print("Your Computer Name is:" + hostname)    
print("Your Computer IP Address is:" + IPAddr) 

But this gives me:

Your Computer Name is:169.254.128.117
Your Computer IP Address is:169.254.128.117

which is not helpful.

How can I know what private IP the lambda function is using?

1
What is the real problem that you're trying to solve?Parsifal

1 Answers

3
votes

Remember that when you configure your Lambda to work within a VPC, it is actually attached to the VPC (in fact it is running in an AWS managed VPC).

Instead you get an ENI for each Lambda through which the Lambda will speak for its outbound connections, this allows it to connect to your resources in the VPC.

At this time, the value for which availability zone you're running in is not accessible by the Lambda, here is a list of all available environment variables that Lambda has access to.

If you wanted to retrieve the ENI IP of what you were connecting to resources as you would need to communicate outbound to a resource in your VPC and have that return the IP address you connected on.