in migration/bring-your-own-role/byor.py [0:0]
def _copy_tags(source_role_name, dest_role_name, iam_client, execute_flag):
paginator = iam_client.get_paginator('list_role_tags')
tags_to_copy = []
for page in paginator.paginate(RoleName=source_role_name):
for tag in page['Tags']:
if tag['Key'] == 'RoleName' and tag['Value'] == source_role_name:
tag['Value'] = dest_role_name
print(f"Update IAM Role's tag {tag['Key']} value from {source_role_name} to {dest_role_name}\n")
tags_to_copy.append(tag)
if tags_to_copy and execute_flag:
iam_client.tag_role(
RoleName=dest_role_name,
Tags=tags_to_copy
)
print(f"Tags copied successfully to role: `{dest_role_name}`\n")
else:
print(f"Tags to copy to role `{dest_role_name}` would be:")
pprint(tags_to_copy)
print(f"Tags copy skipped for role: `{dest_role_name}`, set --execute flag to True to do the actual update.\n")