Attaches the specified managed policy to the specified IAM group.
You use this operation to attach a managed policy to a group. To embed an inline policy in a group, use PutGroupPolicy .
As a best practice, you can validate your IAM policies. To learn more, see Validating IAM policies in the IAM User Guide.
For more information about policies, see Managed policies and inline policies in the IAM User Guide.
Parameters:
-
group_name
(groupNameType)
–
The name (friendly name, not ARN) of the group to attach the policy to.
This parameter allows (through its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-
-
policy_arn
(arnType)
–
The Amazon Resource Name (ARN) of the IAM policy you want to attach.
For more information about ARNs, see Amazon Resource Names (ARNs) in the Amazon Web Services General Reference.
Raises:
-
InvalidInputException
–
The request was rejected because an invalid or out-of-range value was supplied for an input parameter.
-
LimitExceededException
–
The request was rejected because it attempted to create resources beyond the current Amazon Web Services account limits. The error message describes the limit exceeded.
-
NoSuchEntityException
–
The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.
-
PolicyNotAttachableException
–
The request failed because Amazon Web Services service role policies can only be attached to the service-linked role for that service.
-
ServiceFailureException
–
The request processing has failed because of an unknown error, exception or failure.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Examples:
To attach a managed policy to an IAM group
The following command attaches the AWS managed policy named ReadOnlyAccess to the IAM group named Finance.
>>> client.attach_group_policy(group_name='Finance', policy_arn='arn:aws:iam::aws:policy/ReadOnlyAccess')
Source code in docs_src/capo_iam/_services/iam.py
| def attach_group_policy(
self,
group_name: "capo_iam.types.group_name_type.groupNameType",
policy_arn: "capo_iam.types.arn_type.arnType",
*,
config_overrides: Optional[IAMClientConfig] = None,
) -> None:
"""<p>Attaches the specified managed policy to the specified IAM group.</p> <p>You use this operation to attach a managed policy to a group. To embed an inline policy in a group, use <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_PutGroupPolicy.html"> <code>PutGroupPolicy</code> </a>.</p> <p>As a best practice, you can validate your IAM policies. To learn more, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_policy-validator.html">Validating IAM policies</a> in the <i>IAM User Guide</i>.</p> <p>For more information about policies, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/policies-managed-vs-inline.html">Managed policies and inline policies</a> in the <i>IAM User Guide</i>.</p>
Args:
group_name: <p>The name (friendly name, not ARN) of the group to attach the policy to.</p> <p>This parameter allows (through its <a href="http://wikipedia.org/wiki/regex">regex pattern</a>) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-</p>
policy_arn: <p>The Amazon Resource Name (ARN) of the IAM policy you want to attach.</p> <p>For more information about ARNs, see <a href="https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html">Amazon Resource Names (ARNs)</a> in the <i>Amazon Web Services General Reference</i>.</p>
Raises:
capo_iam.errors.invalid_input_exception.InvalidInputException: <p>The request was rejected because an invalid or out-of-range value was supplied for an input parameter.</p>
capo_iam.errors.limit_exceeded_exception.LimitExceededException: <p>The request was rejected because it attempted to create resources beyond the current Amazon Web Services account limits. The error message describes the limit exceeded.</p>
capo_iam.errors.no_such_entity_exception.NoSuchEntityException: <p>The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.</p>
capo_iam.errors.policy_not_attachable_exception.PolicyNotAttachableException: <p>The request failed because Amazon Web Services service role policies can only be attached to the service-linked role for that service.</p>
capo_iam.errors.service_failure_exception.ServiceFailureException: <p>The request processing has failed because of an unknown error, exception or failure.</p>
capo_iam.errors.UnknownServiceError: The service returned an error code this client does not model.
Examples:
To attach a managed policy to an IAM group
The following command attaches the AWS managed policy named ReadOnlyAccess to the IAM group named Finance.
>>> client.attach_group_policy(group_name='Finance', policy_arn='arn:aws:iam::aws:policy/ReadOnlyAccess')
"""
def _handler(
req: "OperationRequest[capo_iam.types.attach_group_policy_request.AttachGroupPolicyRequest]",
) -> OperationResponse[None]:
import capo_iam._operations.aws_identity_management_v20100508.attach_group_policy
output, http_response = (
capo_iam._operations.aws_identity_management_v20100508.attach_group_policy.attach_group_policy(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("AttachGroupPolicy")
)
input_: capo_iam.types.attach_group_policy_request.AttachGroupPolicyRequest = {
"group_name": group_name,
"policy_arn": policy_arn,
}
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|