Skip to content

add_custom_attributes async

add_custom_attributes(
    user_pool_id: UserPoolIdType,
    custom_attributes: CustomAttributesListType,
    *,
    config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
) -> AddCustomAttributesResponse

Adds additional user attributes to the user pool schema. Custom attributes can be mutable or immutable and have a custom: or dev: prefix. For more information, see Custom attributes.

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 where you want to add custom attributes.

  • custom_attributes (CustomAttributesListType) –

    An array of custom attribute names and other properties. Sets the following characteristics:

    AttributeDataType

    The expected data type. Can be a string, a number, a date and time, or a boolean.

    Mutable

    If true, you can grant app clients write access to the attribute value. If false, the attribute value can only be set up on sign-up or administrator creation of users.

    Name

    The attribute name. For an attribute like custom:myAttribute, enter myAttribute for this field.

    Required

    When true, users who sign up or are created must set a value for the attribute.

    NumberAttributeConstraints

    The minimum and maximum length of accepted values for a Number-type attribute.

    StringAttributeConstraints

    The minimum and maximum length of accepted values for a String-type attribute.

    DeveloperOnlyAttribute

    This legacy option creates an attribute with a dev: prefix. You can only set the value of a developer-only attribute with administrative IAM credentials.

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.

  • UserImportInProgressException –

    This exception is thrown when you're trying to modify a user pool while a user import job is in progress for that pool.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_cognito_identity_provider/_services/async_cognito_identity_provider.py
async def add_custom_attributes(
    self,
    user_pool_id: "capo_cognito_identity_provider.types.user_pool_id_type.UserPoolIdType",
    custom_attributes: "capo_cognito_identity_provider.types.custom_attributes_list_type.CustomAttributesListType",
    *,
    config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
) -> "capo_cognito_identity_provider.types.add_custom_attributes_response.AddCustomAttributesResponse":
    """<p>Adds additional user attributes to the user pool schema. Custom attributes can be mutable or immutable and have a <code>custom:</code> or <code>dev:</code> prefix. For more information, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-custom-attributes">Custom attributes</a>.</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 where you want to add custom attributes.</p>
        custom_attributes: <p>An array of custom attribute names and other properties. Sets the following characteristics:</p> <dl> <dt>AttributeDataType</dt> <dd> <p>The expected data type. Can be a string, a number, a date and time, or a boolean.</p> </dd> <dt>Mutable</dt> <dd> <p>If true, you can grant app clients write access to the attribute value. If false, the attribute value can only be set up on sign-up or administrator creation of users.</p> </dd> <dt>Name</dt> <dd> <p>The attribute name. For an attribute like <code>custom:myAttribute</code>, enter <code>myAttribute</code> for this field.</p> </dd> <dt>Required</dt> <dd> <p>When true, users who sign up or are created must set a value for the attribute.</p> </dd> <dt>NumberAttributeConstraints</dt> <dd> <p>The minimum and maximum length of accepted values for a <code>Number</code>-type attribute.</p> </dd> <dt>StringAttributeConstraints</dt> <dd> <p>The minimum and maximum length of accepted values for a <code>String</code>-type attribute.</p> </dd> <dt>DeveloperOnlyAttribute</dt> <dd> <p>This legacy option creates an attribute with a <code>dev:</code> prefix. You can only set the value of a developer-only attribute with administrative IAM credentials.</p> </dd> </dl>

    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_import_in_progress_exception.UserImportInProgressException: <p>This exception is thrown when you're trying to modify a user pool while a user import job is in progress for that pool.</p>
        capo_cognito_identity_provider.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_cognito_identity_provider.types.add_custom_attributes_request.AddCustomAttributesRequest]",
    ) -> AsyncOperationResponse[
        "capo_cognito_identity_provider.types.add_custom_attributes_response.AddCustomAttributesResponse"
    ]:
        import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.add_custom_attributes

        (
            output,
            http_response,
        ) = await capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.add_custom_attributes.async_add_custom_attributes(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AddCustomAttributes")
    )
    input_: capo_cognito_identity_provider.types.add_custom_attributes_request.AddCustomAttributesRequest = {
        "user_pool_id": user_pool_id,
        "custom_attributes": custom_attributes,
    }

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output