0

I'm trying to load properties file in my Lambda written in Java. I understand I can pass environment variables e.g env dev, test, stage, prod etc. and in lambda load respective properties file according to environment in which lambda is running. But this Lambda will be running under multiple AWS accounts in China region as well which currently do not support passing env variables to Lambda.

I was thinking I can figure out the AWS account number from API and based on account number I can load the correct properties file for that environment, will that be the right way to solve this issue. Suppose later I have to run the Lambda code in another environment that will require changing the code.

[Update]

Looks like I can extract the Account number from context variable available to handler

    context.getInvokedFunctionArn()

e.g. arn:aws:lambda:us-east-1:999999999999:function:my_lambda_function

1 Answer 1

0

You can use AWS Service STS and use GetCallerIdentity API call. This will you Account number in response. Using the Account number, you can load the configuration in your code.

Create a new role with policy: { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": "sts:GetCallerIdentity", "Resource": "*" } ] }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.