Skip to content

Instantly share code, notes, and snippets.

@aws-scripting-guy
Created March 6, 2016 23:49
Show Gist options
  • Save aws-scripting-guy/83d901527fa7adc271da to your computer and use it in GitHub Desktop.
Save aws-scripting-guy/83d901527fa7adc271da to your computer and use it in GitHub Desktop.
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
@jnewbigin
Copy link

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