Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get AWS account id inside Lambda function programmatically - python
def lambda_handler(event, context):
# Get Account Id from lambda function arn
print "lambda arn: " + context.invoked_function_arn
# Get Account ID from lambda function arn in the context
ACCOUNT_ID = context.invoked_function_arn.split(":")[4]
print "Account ID=" + ACCOUNT_ID

This comment has been minimized.

Copy link

@jnewbigin jnewbigin commented Feb 11, 2019

Once you rely on context... you need to make sure you fake it up from the command line and test invocations
or catch errors and substitute something else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment