Attaches a policy to a user. :param user_name: The name of the user. :param policy_arn: The Amazon Resource Name (ARN) of the policy.
(user_name, policy_arn)
| 106 | |
| 107 | # snippet-start:[python.example_code.iam.AttachUserPolicy] |
| 108 | def attach_policy(user_name, policy_arn): |
| 109 | """ |
| 110 | Attaches a policy to a user. |
| 111 | |
| 112 | :param user_name: The name of the user. |
| 113 | :param policy_arn: The Amazon Resource Name (ARN) of the policy. |
| 114 | """ |
| 115 | try: |
| 116 | iam.User(user_name).attach_policy(PolicyArn=policy_arn) |
| 117 | logger.info("Attached policy %s to user %s.", policy_arn, user_name) |
| 118 | except ClientError: |
| 119 | logger.exception("Couldn't attach policy %s to user %s.", policy_arn, user_name) |
| 120 | raise |
| 121 | |
| 122 | |
| 123 | # snippet-end:[python.example_code.iam.AttachUserPolicy] |
no test coverage detected