1
votes

I am having an AWS lambda function with Java8 as programming language which needs access to AWS VPC resources and my VPC has multiple AZ (Availability Zones) under it.

When I know the Availability Zone details where my lambda function is currently running (want to figure out this within the lambda function itself using Context Object or from Environment Variables), I can connect to the resources in the local AZ first and do fail over to other AZ if needed. This avoids data transfer between the AZ most of the time.

Is there any way to get the AZ details from within the lambda code itself ?

2
as per my knowledge you need to create amazon availability zone to access your resources from aws console only with your valid credentials.Pradeep
docs.aws.amazon.com/AmazonRDS/latest/UserGuide/… please refer to this guide for availability zones details.Pradeep
@Pradeep your comments are not relevant to the question.Mark B
Lambda can't likely tell you which availability zone of yours that it is running in, because my us-east-2a may actually be your us-east-2b or -2c. If the Lambda container knows its zone, that information would probably be in a form that would not be meaningful from your perspective.Michael - sqlbot
@Michael even I was thinking the same that's why I hav asked him to create on aws console and expose that api in his code .@Mark maybe I was wrong but what Michael suggested I would go with thatPradeep

2 Answers

1
votes

Not for Lambda. For EC2 check out http://169.254.169.254/latest/meta-data/placement/availability-zone. ECS allows you access to a more limited set via cat $ECS_CONTAINER_METADATA_FILE which doesn’t include AZ.

0
votes

A workaround would be to try to get the Lambda's IP address (could do it using an HTTP call to a server in the VPC), then use that to look up the corresponding subnet that it's running in. If you know the subnet, you know the AZ (assuming you created the subnets).