in projects/enable-irsa/src/main.py [0:0]
def create_iam_role(RoleName: str, TrustPolicy: dict):
print('Creating IAM role.')
try:
role = iam.create_role(
RoleName=RoleName,
AssumeRolePolicyDocument=json.dumps(TrustPolicy)
)
except iam.exceptions.InvalidInputException:
print('Invalid input.')
exit(1)
except iam.exceptions.MalformedPolicyDocumentException:
print('Malformed policy document')
exit(1)
except iam.exceptions.EntityAlreadyExistsException:
print('Role already exists. Getting Arn.')
role_arn = iam.get_role(RoleName=RoleName)['Role']['Arn']
return role_arn
return role['Role']['Arn']