Created
March 6, 2016 23:49
-
-
Save aws-scripting-guy/83d901527fa7adc271da to your computer and use it in GitHub Desktop.
Get AWS account id inside Lambda function programmatically - python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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