Skip to content

get_random_password async

get_random_password(
    *,
    config_overrides: Optional[AsyncSecretsManagerClientConfig] = None,
    password_length: Optional[PasswordLengthType] = None,
    exclude_characters: Optional[ExcludeCharactersType] = None,
    exclude_numbers: Optional[ExcludeNumbersType] = None,
    exclude_punctuation: Optional[ExcludePunctuationType] = None,
    exclude_uppercase: Optional[ExcludeUppercaseType] = None,
    exclude_lowercase: Optional[ExcludeLowercaseType] = None,
    include_space: Optional[IncludeSpaceType] = None,
    require_each_included_type: Optional[RequireEachIncludedTypeType] = None,
) -> GetRandomPasswordResponse

Generates a random password. We recommend that you specify the maximum length and include every character type that the system you are generating a password for can support. By default, Secrets Manager uses uppercase and lowercase letters, numbers, and the following characters in passwords: !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~

Secrets Manager generates a CloudTrail log entry when you call this action.

Required permissions: secretsmanager:GetRandomPassword. For more information, see IAM policy actions for Secrets Manager and Authentication and access control in Secrets Manager.

Parameters:

  • password_length (Optional[PasswordLengthType], default: None ) –

    The length of the password. If you don't include this parameter, the default length is 32 characters.

  • exclude_characters (Optional[ExcludeCharactersType], default: None ) –

    A string of the characters that you don't want in the password.

  • exclude_numbers (Optional[ExcludeNumbersType], default: None ) –

    Specifies whether to exclude numbers from the password. If you don't include this switch, the password can contain numbers.

  • exclude_punctuation (Optional[ExcludePunctuationType], default: None ) –

    Specifies whether to exclude the following punctuation characters from the password: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~. If you don't include this switch, the password can contain punctuation.

  • exclude_uppercase (Optional[ExcludeUppercaseType], default: None ) –

    Specifies whether to exclude uppercase letters from the password. If you don't include this switch, the password can contain uppercase letters.

  • exclude_lowercase (Optional[ExcludeLowercaseType], default: None ) –

    Specifies whether to exclude lowercase letters from the password. If you don't include this switch, the password can contain lowercase letters.

  • include_space (Optional[IncludeSpaceType], default: None ) –

    Specifies whether to include the space character. If you include this switch, the password can contain space characters.

  • require_each_included_type (Optional[RequireEachIncludedTypeType], default: None ) –

    Specifies whether to include at least one upper and lowercase letter, one number, and one punctuation. If you don't include this switch, the password contains at least one of every character type.

Raises:

  • InternalServiceError –

    An error occurred on the server side.

  • InvalidParameterException –

    The parameter name or value is invalid.

  • InvalidRequestException –

    A parameter value is not valid for the current state of the resource.

    Possible causes:

    • The secret is scheduled for deletion.

    • You tried to enable rotation on a secret that doesn't already have a Lambda function ARN configured and you didn't include such an ARN as a parameter in this call.

    • The secret is managed by another service, and you must use that service to update it. For more information, see Secrets managed by other Amazon Web Services services.

  • UnknownServiceError –

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

Examples:

To generate a random password The following example shows how to request a randomly generated password. This example includes the optional flags to require spaces and at least one character of each included type. It specifies a length of 20 characters.

>>> await client.get_random_password(password_length=20, include_space=True, require_each_included_type=True)
Source code in docs_src/capo_secrets_manager/_services/async_secrets_manager.py
async def get_random_password(
    self,
    *,
    config_overrides: Optional[AsyncSecretsManagerClientConfig] = None,
    password_length: Optional[
        "capo_secrets_manager.types.password_length_type.PasswordLengthType"
    ] = None,
    exclude_characters: Optional[
        "capo_secrets_manager.types.exclude_characters_type.ExcludeCharactersType"
    ] = None,
    exclude_numbers: Optional[
        "capo_secrets_manager.types.exclude_numbers_type.ExcludeNumbersType"
    ] = None,
    exclude_punctuation: Optional[
        "capo_secrets_manager.types.exclude_punctuation_type.ExcludePunctuationType"
    ] = None,
    exclude_uppercase: Optional[
        "capo_secrets_manager.types.exclude_uppercase_type.ExcludeUppercaseType"
    ] = None,
    exclude_lowercase: Optional[
        "capo_secrets_manager.types.exclude_lowercase_type.ExcludeLowercaseType"
    ] = None,
    include_space: Optional[
        "capo_secrets_manager.types.include_space_type.IncludeSpaceType"
    ] = None,
    require_each_included_type: Optional[
        "capo_secrets_manager.types.require_each_included_type_type.RequireEachIncludedTypeType"
    ] = None,
) -> "capo_secrets_manager.types.get_random_password_response.GetRandomPasswordResponse":
    r"""<p>Generates a random password. We recommend that you specify the maximum length and include every character type that the system you are generating a password for can support. By default, Secrets Manager uses uppercase and lowercase letters, numbers, and the following characters in passwords: <code>!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~</code> </p> <p>Secrets Manager generates a CloudTrail log entry when you call this action.</p> <p> <b>Required permissions: </b> <code>secretsmanager:GetRandomPassword</code>. For more information, see <a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/reference_iam-permissions.html#reference_iam-permissions_actions"> IAM policy actions for Secrets Manager</a> and <a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access.html">Authentication and access control in Secrets Manager</a>. </p>

    Args:
        password_length: <p>The length of the password. If you don't include this parameter, the default length is 32 characters.</p>
        exclude_characters: <p>A string of the characters that you don't want in the password.</p>
        exclude_numbers: <p>Specifies whether to exclude numbers from the password. If you don't include this switch, the password can contain numbers.</p>
        exclude_punctuation: <p>Specifies whether to exclude the following punctuation characters from the password: <code>! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~</code>. If you don't include this switch, the password can contain punctuation.</p>
        exclude_uppercase: <p>Specifies whether to exclude uppercase letters from the password. If you don't include this switch, the password can contain uppercase letters.</p>
        exclude_lowercase: <p>Specifies whether to exclude lowercase letters from the password. If you don't include this switch, the password can contain lowercase letters.</p>
        include_space: <p>Specifies whether to include the space character. If you include this switch, the password can contain space characters.</p>
        require_each_included_type: <p>Specifies whether to include at least one upper and lowercase letter, one number, and one punctuation. If you don't include this switch, the password contains at least one of every character type.</p>

    Raises:
        capo_secrets_manager.errors.internal_service_error.InternalServiceError: <p>An error occurred on the server side.</p>
        capo_secrets_manager.errors.invalid_parameter_exception.InvalidParameterException: <p>The parameter name or value is invalid.</p>
        capo_secrets_manager.errors.invalid_request_exception.InvalidRequestException: <p>A parameter value is not valid for the current state of the resource.</p> <p>Possible causes:</p> <ul> <li> <p>The secret is scheduled for deletion.</p> </li> <li> <p>You tried to enable rotation on a secret that doesn't already have a Lambda function ARN configured and you didn't include such an ARN as a parameter in this call. </p> </li> <li> <p>The secret is managed by another service, and you must use that service to update it. For more information, see <a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/service-linked-secrets.html">Secrets managed by other Amazon Web Services services</a>.</p> </li> </ul>
        capo_secrets_manager.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To generate a random password
        The following example shows how to request a randomly generated password. This example includes the optional flags to require spaces and at least one character of each included type. It specifies a length of 20 characters.

        >>> await client.get_random_password(password_length=20, include_space=True, require_each_included_type=True)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_secrets_manager.types.get_random_password_request.GetRandomPasswordRequest]",
    ) -> AsyncOperationResponse[
        "capo_secrets_manager.types.get_random_password_response.GetRandomPasswordResponse"
    ]:
        import capo_secrets_manager._operations.secretsmanager.get_random_password

        (
            output,
            http_response,
        ) = await capo_secrets_manager._operations.secretsmanager.get_random_password.async_get_random_password(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_output(
        output: "capo_secrets_manager.types.get_random_password_response.GetRandomPasswordResponse",
    ) -> dict[str, Any]:
        import capo_secrets_manager.types.get_random_password_response

        return capo_secrets_manager.types.get_random_password_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("GetRandomPassword", redact_output=_redact_output),
    )
    input_: capo_secrets_manager.types.get_random_password_request.GetRandomPasswordRequest = {}
    if password_length is not None:
        input_["password_length"] = password_length
    if exclude_characters is not None:
        input_["exclude_characters"] = exclude_characters
    if exclude_numbers is not None:
        input_["exclude_numbers"] = exclude_numbers
    if exclude_punctuation is not None:
        input_["exclude_punctuation"] = exclude_punctuation
    if exclude_uppercase is not None:
        input_["exclude_uppercase"] = exclude_uppercase
    if exclude_lowercase is not None:
        input_["exclude_lowercase"] = exclude_lowercase
    if include_space is not None:
        input_["include_space"] = include_space
    if require_each_included_type is not None:
        input_["require_each_included_type"] = require_each_included_type

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