SecretsManager / Client / get_random_password

get_random_password#

SecretsManager.Client.get_random_password(**kwargs)#

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.

See also: AWS API Documentation

Request Syntax

response = client.get_random_password(
    PasswordLength=123,
    ExcludeCharacters='string',
    ExcludeNumbers=True|False,
    ExcludePunctuation=True|False,
    ExcludeUppercase=True|False,
    ExcludeLowercase=True|False,
    IncludeSpace=True|False,
    RequireEachIncludedType=True|False
)
Parameters:
  • PasswordLength (integer) – The length of the password. If you don’t include this parameter, the default length is 32 characters.

  • ExcludeCharacters (string) – A string of the characters that you don’t want in the password.

  • ExcludeNumbers (boolean) – Specifies whether to exclude numbers from the password. If you don’t include this switch, the password can contain numbers.

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

  • ExcludeUppercase (boolean) – Specifies whether to exclude uppercase letters from the password. If you don’t include this switch, the password can contain uppercase letters.

  • ExcludeLowercase (boolean) – Specifies whether to exclude lowercase letters from the password. If you don’t include this switch, the password can contain lowercase letters.

  • IncludeSpace (boolean) – Specifies whether to include the space character. If you include this switch, the password can contain space characters.

  • RequireEachIncludedType (boolean) – 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.

Return type:

dict

Returns:

Response Syntax

{
    'RandomPassword': 'string'
}

Response Structure

  • (dict) –

    • RandomPassword (string) –

      A string with the password.

Exceptions

Examples

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.

response = client.get_random_password(
    IncludeSpace=True,
    PasswordLength=20,
    RequireEachIncludedType=True,
)

print(response)

Expected Output:

{
    'RandomPassword': 'EXAMPLE-PASSWORD',
    'ResponseMetadata': {
        '...': '...',
    },
}