Skip to content

update_access_key async

update_access_key(
    access_key_id: accessKeyIdType,
    status: statusType,
    *,
    config_overrides: Optional[AsyncIAMClientConfig] = None,
    user_name: Optional[existingUserNameType] = None,
) -> None

Changes the status of the specified access key from Active to Inactive, or vice versa. This operation can be used to disable a user's key as part of a key rotation workflow.

If the UserName is not specified, the user name is determined implicitly based on the Amazon Web Services access key ID used to sign the request. If a temporary access key is used, then UserName is required. If a long-term key is assigned to the user, then UserName is not required. This operation works for access keys under the Amazon Web Services account. Consequently, you can use this operation to manage Amazon Web Services account root user credentials even if the Amazon Web Services account has no associated users.

For information about rotating keys, see Managing keys and certificates in the IAM User Guide.

Parameters:

  • user_name (Optional[existingUserNameType], default: None ) –

    The name of the user whose key you want to update.

    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: _+=,.@-

  • access_key_id (accessKeyIdType) –

    The access key ID of the secret access key you want to update.

    This parameter allows (through its regex pattern) a string of characters that can consist of any upper or lowercased letter or digit.

  • status (statusType) –

    The status you want to assign to the secret access key. Active means that the key can be used for programmatic calls to Amazon Web Services, while Inactive means that the key cannot be used.

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.

  • 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 activate or deactivate an access key for an IAM user The following command deactivates the specified access key (access key ID and secret access key) for the IAM user named Bob.

>>> await client.update_access_key(user_name='Bob', status='Inactive', access_key_id='AKIAIOSFODNN7EXAMPLE')
Source code in docs_src/capo_iam/_services/async_iam.py
async def update_access_key(
    self,
    access_key_id: "capo_iam.types.access_key_id_type.accessKeyIdType",
    status: "capo_iam.types.status_type.statusType",
    *,
    config_overrides: Optional[AsyncIAMClientConfig] = None,
    user_name: Optional[
        "capo_iam.types.existing_user_name_type.existingUserNameType"
    ] = None,
) -> None:
    """<p>Changes the status of the specified access key from Active to Inactive, or vice versa. This operation can be used to disable a user's key as part of a key rotation workflow.</p> <p>If the <code>UserName</code> is not specified, the user name is determined implicitly based on the Amazon Web Services access key ID used to sign the request. If a temporary access key is used, then <code>UserName</code> is required. If a long-term key is assigned to the user, then <code>UserName</code> is not required. This operation works for access keys under the Amazon Web Services account. Consequently, you can use this operation to manage Amazon Web Services account root user credentials even if the Amazon Web Services account has no associated users.</p> <p>For information about rotating keys, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/ManagingCredentials.html">Managing keys and certificates</a> in the <i>IAM User Guide</i>.</p>

    Args:
        user_name: <p>The name of the user whose key you want to update.</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>
        access_key_id: <p>The access key ID of the secret access key you want to update.</p> <p>This parameter allows (through its <a href="http://wikipedia.org/wiki/regex">regex pattern</a>) a string of characters that can consist of any upper or lowercased letter or digit.</p>
        status: <p> The status you want to assign to the secret access key. <code>Active</code> means that the key can be used for programmatic calls to Amazon Web Services, while <code>Inactive</code> means that the key cannot be used.</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.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 activate or deactivate an access key for an IAM user
        The following command deactivates the specified access key (access key ID and secret access key) for the IAM user named Bob.

        >>> await client.update_access_key(user_name='Bob', status='Inactive', access_key_id='AKIAIOSFODNN7EXAMPLE')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_iam.types.update_access_key_request.UpdateAccessKeyRequest]",
    ) -> AsyncOperationResponse[None]:
        import capo_iam._operations.aws_identity_management_v20100508.update_access_key

        (
            output,
            http_response,
        ) = await capo_iam._operations.aws_identity_management_v20100508.update_access_key.async_update_access_key(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("UpdateAccessKey")
    )
    input_: capo_iam.types.update_access_key_request.UpdateAccessKeyRequest = {
        "access_key_id": access_key_id,
        "status": status,
    }
    if user_name is not None:
        input_["user_name"] = user_name

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