SecretsManager / Client / list_secret_version_ids

list_secret_version_ids#

SecretsManager.Client.list_secret_version_ids(**kwargs)#

Lists the versions of a secret. Secrets Manager uses staging labels to indicate the different versions of a secret. For more information, see Secrets Manager concepts: Versions.

To list the secrets in the account, use ListSecrets.

Secrets Manager generates a CloudTrail log entry when you call this action. Do not include sensitive information in request parameters because it might be logged. For more information, see Logging Secrets Manager events with CloudTrail.

**Required permissions: ** secretsmanager:ListSecretVersionIds. 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.list_secret_version_ids(
    SecretId='string',
    MaxResults=123,
    NextToken='string',
    IncludeDeprecated=True|False
)
Parameters:
  • SecretId (string) –

    [REQUIRED]

    The ARN or name of the secret whose versions you want to list.

    For an ARN, we recommend that you specify a complete ARN rather than a partial ARN. See Finding a secret from a partial ARN.

  • MaxResults (integer) –

    The number of results to include in the response.

    If there are more results available, in the response, Secrets Manager includes NextToken. To get the next results, call ListSecretVersionIds again with the value from NextToken.

  • NextToken (string) – A token that indicates where the output should continue from, if a previous call did not show all results. To get the next results, call ListSecretVersionIds again with this value.

  • IncludeDeprecated (boolean) – Specifies whether to include versions of secrets that don’t have any staging labels attached to them. Versions without staging labels are considered deprecated and are subject to deletion by Secrets Manager.

Return type:

dict

Returns:

Response Syntax

{
    'Versions': [
        {
            'VersionId': 'string',
            'VersionStages': [
                'string',
            ],
            'LastAccessedDate': datetime(2015, 1, 1),
            'CreatedDate': datetime(2015, 1, 1),
            'KmsKeyIds': [
                'string',
            ]
        },
    ],
    'NextToken': 'string',
    'ARN': 'string',
    'Name': 'string'
}

Response Structure

  • (dict) –

    • Versions (list) –

      A list of the versions of the secret.

      • (dict) –

        A structure that contains information about one version of a secret.

        • VersionId (string) –

          The unique version identifier of this version of the secret.

        • VersionStages (list) –

          An array of staging labels that are currently associated with this version of the secret.

          • (string) –

        • LastAccessedDate (datetime) –

          The date that this version of the secret was last accessed. Note that the resolution of this field is at the date level and does not include the time.

        • CreatedDate (datetime) –

          The date and time this version of the secret was created.

        • KmsKeyIds (list) –

          The KMS keys used to encrypt the secret version.

          • (string) –

    • NextToken (string) –

      Secrets Manager includes this value if there’s more output available than what is included in the current response. This can occur even when the response includes no values at all, such as when you ask for a filtered view of a long list. To get the next results, call ListSecretVersionIds again with this value.

    • ARN (string) –

      The ARN of the secret.

    • Name (string) –

      The name of the secret.

Exceptions

  • SecretsManager.Client.exceptions.InvalidNextTokenException

  • SecretsManager.Client.exceptions.ResourceNotFoundException

  • SecretsManager.Client.exceptions.InternalServiceError

  • SecretsManager.Client.exceptions.InvalidParameterException

Examples

The following example shows how to retrieve a list of all of the versions of a secret, including those without any staging labels.

response = client.list_secret_version_ids(
    IncludeDeprecated=True,
    SecretId='MyTestDatabaseSecret',
)

print(response)

Expected Output:

{
    'ARN': 'arn:aws:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3',
    'Name': 'MyTestDatabaseSecret',
    'Versions': [
        {
            'CreatedDate': 1523477145.713,
            'VersionId': 'EXAMPLE1-90ab-cdef-fedc-ba987EXAMPLE',
            'VersionStages': [
                'AWSPREVIOUS',
            ],
        },
        {
            'CreatedDate': 1523486221.391,
            'VersionId': 'EXAMPLE2-90ab-cdef-fedc-ba987EXAMPLE',
            'VersionStages': [
                'AWSCURRENT',
            ],
        },
        {
            'CreatedDate': 1511974462.36,
            'VersionId': 'EXAMPLE3-90ab-cdef-fedc-ba987EXAMPLE;',
        },
    ],
    'ResponseMetadata': {
        '...': '...',
    },
}