Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda Meta-Data like EC2 Meta-Data for lambda

AWS EC2 Meta-Data provides the necessary information about itself from EC2 (duh!) - is there anything equivalent for lambda.

I understand the multi-tenancy and short-lived behavior of the lambda function unlike EC2 but essential info like Account ID, VPC AZ, Region would help do a lot of AWS automation.

like image 746
Naveen Vijay Avatar asked Jul 19 '16 17:07

Naveen Vijay


2 Answers

No, unfortunately not. The context object is the closest thing, but the information it offers is very limited. http://docs.aws.amazon.com/lambda/latest/dg/programming-model-v2.html

If you're invoking the lambda functions yourself or in a programmatic way, you could pass the account ID and region in the payload.

like image 113
Karen B Avatar answered Oct 29 '22 12:10

Karen B


You can set an environment variable when you deploy the lambda: https://docs.aws.amazon.com/lambda/latest/dg/env_variables.html

There are already AWS_REGION and AWS_DEFAULT_REGION variables there: https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html#lambda-environment-variables.

event can have fields like requestContext.accountId: https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html?shortFooter=true#eventsources-api-gateway-request

Found this out when browsing Terraform's lambda_function configuration.

like image 37
Victor Sergienko Avatar answered Oct 29 '22 12:10

Victor Sergienko