Skip to content

Instantly share code, notes, and snippets.

@it-am
Last active October 21, 2018 22:11
Show Gist options
  • Save it-am/11251a06f9cf37fc766fe43504d1ac5d to your computer and use it in GitHub Desktop.
Save it-am/11251a06f9cf37fc766fe43504d1ac5d to your computer and use it in GitHub Desktop.
medium
import boto3
import json
client = boto3.client('lambda')
ssm_client = boto3.client('ssm')
def lambda_handler(event, context):
# -----------------------------------------------------------------------
# Get the list of ARNs of cross-account IAM roles saved in SSM Parameter rolearnlist
# -----------------------------------------------------------------------
rolearnlist = []
rolearnlist_from_ssm = ssm_client.get_parameter(Name='rolearnlist')
rolearnlist_from_ssm_list = rolearnlist_from_ssm['Parameter']['Value'].split(",")
rolearnlist = rolearnlist_from_ssm_list
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
# Loop through the list of ARNs, asynchronously invoke invoke_slave lambda and pass ARN
# -----------------------------------------------------------------------
for rolearn in rolearnlist:
x = {"ARN": rolearn}
invoke_response = client.invoke(FunctionName="invoke_slave",
InvocationType='Event', #assync exec
#InvocationType='RequestResponse', #sync exec
Payload=json.dumps(x))
print(invoke_response)
# -----------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment