MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / attach_policy

Function attach_policy

python/example_code/iam/user_wrapper.py:108–120  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

106
107# snippet-start:[python.example_code.iam.AttachUserPolicy]
108def 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]

Callers 1

usage_demoFunction · 0.70

Calls 1

attach_policyMethod · 0.80

Tested by

no test coverage detected