Adds a user to a group. A user who is in a group can present a preferred-role claim to an identity pool, and populates a cognito:groups claim to their access and identity tokens.
Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.
Learn more
Parameters:
-
user_pool_id
(UserPoolIdType)
–
The ID of the user pool that contains the group that you want to add the user to.
-
username
(UsernameType)
–
The name of the user that you want to query or modify. The value of this parameter is typically your user's username, but it can be any of their alias attributes. If username isn't an alias attribute in your user pool, this value must be the sub of a local user or the username of a user from a third-party IdP.
-
group_name
(GroupNameType)
–
The name of the group that you want to add your user to.
Raises:
-
InternalErrorException
–
This exception is thrown when Amazon Cognito encounters an internal error.
-
InvalidParameterException
–
This exception is thrown when the Amazon Cognito service encounters an invalid parameter.
-
NotAuthorizedException
–
This exception is thrown when a user isn't authorized.
-
OperationNotEnabledException
–
This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.
-
ResourceNotFoundException
–
This exception is thrown when the Amazon Cognito service can't find the requested resource.
-
TooManyRequestsException
–
This exception is thrown when the user has made too many requests for a given operation.
-
UserNotFoundException
–
This exception is thrown when a user isn't found.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Source code in docs_src/capo_cognito_identity_provider/_services/cognito_identity_provider.py
| def admin_add_user_to_group(
self,
user_pool_id: "capo_cognito_identity_provider.types.user_pool_id_type.UserPoolIdType",
username: "capo_cognito_identity_provider.types.username_type.UsernameType",
group_name: "capo_cognito_identity_provider.types.group_name_type.GroupNameType",
*,
config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
) -> None:
"""<p>Adds a user to a group. A user who is in a group can present a preferred-role claim to an identity pool, and populates a <code>cognito:groups</code> claim to their access and identity tokens.</p> <note> <p>Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.</p> <p class="title"> <b>Learn more</b> </p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-signing.html">Signing Amazon Web Services API Requests</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pools-API-operations.html">Using the Amazon Cognito user pools API and user pool endpoints</a> </p> </li> </ul> </note>
Args:
user_pool_id: <p>The ID of the user pool that contains the group that you want to add the user to.</p>
username: <p>The name of the user that you want to query or modify. The value of this parameter is typically your user's username, but it can be any of their alias attributes. If <code>username</code> isn't an alias attribute in your user pool, this value must be the <code>sub</code> of a local user or the username of a user from a third-party IdP.</p>
group_name: <p>The name of the group that you want to add your user to.</p>
Raises:
capo_cognito_identity_provider.errors.internal_error_exception.InternalErrorException: <p>This exception is thrown when Amazon Cognito encounters an internal error.</p>
capo_cognito_identity_provider.errors.invalid_parameter_exception.InvalidParameterException: <p>This exception is thrown when the Amazon Cognito service encounters an invalid parameter.</p>
capo_cognito_identity_provider.errors.not_authorized_exception.NotAuthorizedException: <p>This exception is thrown when a user isn't authorized.</p>
capo_cognito_identity_provider.errors.operation_not_enabled_exception.OperationNotEnabledException: <p>This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.</p>
capo_cognito_identity_provider.errors.resource_not_found_exception.ResourceNotFoundException: <p>This exception is thrown when the Amazon Cognito service can't find the requested resource.</p>
capo_cognito_identity_provider.errors.too_many_requests_exception.TooManyRequestsException: <p>This exception is thrown when the user has made too many requests for a given operation.</p>
capo_cognito_identity_provider.errors.user_not_found_exception.UserNotFoundException: <p>This exception is thrown when a user isn't found.</p>
capo_cognito_identity_provider.errors.UnknownServiceError: The service returned an error code this client does not model.
"""
def _handler(
req: "OperationRequest[capo_cognito_identity_provider.types.admin_add_user_to_group_request.AdminAddUserToGroupRequest]",
) -> OperationResponse[None]:
import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.admin_add_user_to_group
output, http_response = (
capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.admin_add_user_to_group.admin_add_user_to_group(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
def _redact_input(
input_: "capo_cognito_identity_provider.types.admin_add_user_to_group_request.AdminAddUserToGroupRequest",
) -> dict[str, Any]:
import capo_cognito_identity_provider.types.admin_add_user_to_group_request
return capo_cognito_identity_provider.types.admin_add_user_to_group_request.redact_sensitive(
input_
)
interceptors_, options_ = self.operation_options(
config_overrides,
OperationLogging("AdminAddUserToGroup", redact_input=_redact_input),
)
input_: capo_cognito_identity_provider.types.admin_add_user_to_group_request.AdminAddUserToGroupRequest = {
"user_pool_id": user_pool_id,
"username": username,
"group_name": group_name,
}
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|