Last active
October 21, 2018 22:11
-
-
Save it-am/11251a06f9cf37fc766fe43504d1ac5d to your computer and use it in GitHub Desktop.
medium
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
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