AWS Secrets Manager

2022/12/29 - AWS Secrets Manager - 2 updated api methods

Changes  Added owning service filter, include planned deletion flag, and next rotation date response parameter in ListSecrets.

DescribeSecret (updated) Link ¶
Changes (response)
{'NextRotationDate': 'timestamp'}

Retrieves the details of a secret. It does not include the encrypted secret value. Secrets Manager only returns fields that have a value in the response.

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:DescribeSecret . 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

client.describe_secret(
    SecretId='string'
)
type SecretId

string

param SecretId

[REQUIRED]

The ARN or name of the secret.

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

rtype

dict

returns

Response Syntax

{
    'ARN': 'string',
    'Name': 'string',
    'Description': 'string',
    'KmsKeyId': 'string',
    'RotationEnabled': True|False,
    'RotationLambdaARN': 'string',
    'RotationRules': {
        'AutomaticallyAfterDays': 123,
        'Duration': 'string',
        'ScheduleExpression': 'string'
    },
    'LastRotatedDate': datetime(2015, 1, 1),
    'LastChangedDate': datetime(2015, 1, 1),
    'LastAccessedDate': datetime(2015, 1, 1),
    'DeletedDate': datetime(2015, 1, 1),
    'NextRotationDate': datetime(2015, 1, 1),
    'Tags': [
        {
            'Key': 'string',
            'Value': 'string'
        },
    ],
    'VersionIdsToStages': {
        'string': [
            'string',
        ]
    },
    'OwningService': 'string',
    'CreatedDate': datetime(2015, 1, 1),
    'PrimaryRegion': 'string',
    'ReplicationStatus': [
        {
            'Region': 'string',
            'KmsKeyId': 'string',
            'Status': 'InSync'|'Failed'|'InProgress',
            'StatusMessage': 'string',
            'LastAccessedDate': datetime(2015, 1, 1)
        },
    ]
}

Response Structure

  • (dict) --

    • ARN (string) --

      The ARN of the secret.

    • Name (string) --

      The name of the secret.

    • Description (string) --

      The description of the secret.

    • KmsKeyId (string) --

      The key ID or alias ARN of the KMS key that Secrets Manager uses to encrypt the secret value. If the secret is encrypted with the Amazon Web Services managed key aws/secretsmanager , this field is omitted. Secrets created using the console use an KMS key ID.

    • RotationEnabled (boolean) --

      Specifies whether automatic rotation is turned on for this secret.

      To turn on rotation, use RotateSecret . To turn off rotation, use CancelRotateSecret .

    • RotationLambdaARN (string) --

      The ARN of the Lambda function that Secrets Manager invokes to rotate the secret.

    • RotationRules (dict) --

      The rotation schedule and Lambda function for this secret. If the secret previously had rotation turned on, but it is now turned off, this field shows the previous rotation schedule and rotation function. If the secret never had rotation turned on, this field is omitted.

      • AutomaticallyAfterDays (integer) --

        The number of days between automatic scheduled rotations of the secret. You can use this value to check that your secret meets your compliance guidelines for how often secrets must be rotated.

        In DescribeSecret and ListSecrets , this value is calculated from the rotation schedule after every successful rotation. In RotateSecret , you can set the rotation schedule in RotationRules with AutomaticallyAfterDays or ScheduleExpression , but not both. To set a rotation schedule in hours, use ScheduleExpression .

      • Duration (string) --

        The length of the rotation window in hours, for example 3h for a three hour window. Secrets Manager rotates your secret at any time during this window. The window must not extend into the next rotation window or the next UTC day. The window starts according to the ScheduleExpression . If you don't specify a Duration , for a ScheduleExpression in hours, the window automatically closes after one hour. For a ScheduleExpression in days, the window automatically closes at the end of the UTC day. For more information, including examples, see Schedule expressions in Secrets Manager rotation in the Secrets Manager Users Guide .

      • ScheduleExpression (string) --

        A cron() or rate() expression that defines the schedule for rotating your secret. Secrets Manager rotation schedules use UTC time zone. Secrets Manager rotates your secret any time during a rotation window.

        Secrets Manager rate() expressions represent the interval in hours or days that you want to rotate your secret, for example rate(12 hours) or rate(10 days) . You can rotate a secret as often as every four hours. If you use a rate() expression, the rotation window starts at midnight. For a rate in hours, the default rotation window closes after one hour. For a rate in days, the default rotation window closes at the end of the day. You can set the Duration to change the rotation window. The rotation window must not extend into the next UTC day or into the next rotation window.

        You can use a cron() expression to create a rotation schedule that is more detailed than a rotation interval. For more information, including examples, see Schedule expressions in Secrets Manager rotation in the Secrets Manager Users Guide . For a cron expression that represents a schedule in hours, the default rotation window closes after one hour. For a cron expression that represents a schedule in days, the default rotation window closes at the end of the day. You can set the Duration to change the rotation window. The rotation window must not extend into the next UTC day or into the next rotation window.

    • LastRotatedDate (datetime) --

      The last date and time that Secrets Manager rotated the secret. If the secret isn't configured for rotation, Secrets Manager returns null.

    • LastChangedDate (datetime) --

      The last date and time that this secret was modified in any way.

    • LastAccessedDate (datetime) --

      The date that the secret was last accessed in the Region. This field is omitted if the secret has never been retrieved in the Region.

    • DeletedDate (datetime) --

      The date the secret is scheduled for deletion. If it is not scheduled for deletion, this field is omitted. When you delete a secret, Secrets Manager requires a recovery window of at least 7 days before deleting the secret. Some time after the deleted date, Secrets Manager deletes the secret, including all of its versions.

      If a secret is scheduled for deletion, then its details, including the encrypted secret value, is not accessible. To cancel a scheduled deletion and restore access to the secret, use RestoreSecret .

    • NextRotationDate (datetime) --

    • Tags (list) --

      The list of tags attached to the secret. To add tags to a secret, use TagResource . To remove tags, use UntagResource .

      • (dict) --

        A structure that contains information about a tag.

        • Key (string) --

          The key identifier, or name, of the tag.

        • Value (string) --

          The string value associated with the key of the tag.

    • VersionIdsToStages (dict) --

      A list of the versions of the secret that have staging labels attached. Versions that don't have staging labels are considered deprecated and Secrets Manager can delete them.

      Secrets Manager uses staging labels to indicate the status of a secret version during rotation. The three staging labels for rotation are:

      • AWSCURRENT , which indicates the current version of the secret.

      • AWSPENDING , which indicates the version of the secret that contains new secret information that will become the next current version when rotation finishes. During rotation, Secrets Manager creates an AWSPENDING version ID before creating the new secret version. To check if a secret version exists, call GetSecretValue .

      • AWSPREVIOUS , which indicates the previous current version of the secret. You can use this as the last known good version.

      For more information about rotation and staging labels, see How rotation works .

      • (string) --

        • (list) --

          • (string) --

    • OwningService (string) --

      The ID of the service that created this secret. For more information, see Secrets managed by other Amazon Web Services services .

    • CreatedDate (datetime) --

      The date the secret was created.

    • PrimaryRegion (string) --

      The Region the secret is in. If a secret is replicated to other Regions, the replicas are listed in ReplicationStatus .

    • ReplicationStatus (list) --

      A list of the replicas of this secret and their status:

      • Failed , which indicates that the replica was not created.

      • InProgress , which indicates that Secrets Manager is in the process of creating the replica.

      • InSync , which indicates that the replica was created.

      • (dict) --

        A replication object consisting of a RegionReplicationStatus object and includes a Region, KMSKeyId, status, and status message.

        • Region (string) --

          The Region where replication occurs.

        • KmsKeyId (string) --

          Can be an ARN , Key ID , or Alias .

        • Status (string) --

          The status can be InProgress , Failed , or InSync .

        • StatusMessage (string) --

          Status message such as "Secret with this name already exists in this region ".

        • LastAccessedDate (datetime) --

          The date that the secret was last accessed in the Region. This field is omitted if the secret has never been retrieved in the Region.

ListSecrets (updated) Link ¶
Changes (request, response)
Request
{'Filters': {'Key': {'owning-service'}}, 'IncludePlannedDeletion': 'boolean'}
Response
{'SecretList': {'NextRotationDate': 'timestamp'}}

Lists the secrets that are stored by Secrets Manager in the Amazon Web Services account, not including secrets that are marked for deletion. To see secrets marked for deletion, use the Secrets Manager console.

ListSecrets is eventually consistent, however it might not reflect changes from the last five minutes. To get the latest information for a specific secret, use DescribeSecret .

To list the versions of a secret, use ListSecretVersionIds .

To get the secret value from SecretString or SecretBinary , call GetSecretValue .

For information about finding secrets in the console, see Find secrets in Secrets Manager .

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:ListSecrets . 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

client.list_secrets(
    IncludePlannedDeletion=True|False,
    MaxResults=123,
    NextToken='string',
    Filters=[
        {
            'Key': 'description'|'name'|'tag-key'|'tag-value'|'primary-region'|'owning-service'|'all',
            'Values': [
                'string',
            ]
        },
    ],
    SortOrder='asc'|'desc'
)
type IncludePlannedDeletion

boolean

param IncludePlannedDeletion

type MaxResults

integer

param MaxResults

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 ListSecrets again with the value from NextToken .

type NextToken

string

param NextToken

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 ListSecrets again with this value.

type Filters

list

param Filters

The filters to apply to the list of secrets.

  • (dict) --

    Allows you to add filters when you use the search function in Secrets Manager. For more information, see Find secrets in Secrets Manager .

    • Key (string) --

      The following are keys you can use:

      • description : Prefix match, not case-sensitive.

      • name : Prefix match, case-sensitive.

      • tag-key : Prefix match, case-sensitive.

      • tag-value : Prefix match, case-sensitive.

      • primary-region : Prefix match, case-sensitive.

      • all : Breaks the filter value string into words and then searches all attributes for matches. Not case-sensitive.

    • Values (list) --

      The keyword to filter for.

      You can prefix your search value with an exclamation mark (! ) in order to perform negation filters.

      • (string) --

type SortOrder

string

param SortOrder

Secrets are listed by CreatedDate .

rtype

dict

returns

Response Syntax

{
    'SecretList': [
        {
            'ARN': 'string',
            'Name': 'string',
            'Description': 'string',
            'KmsKeyId': 'string',
            'RotationEnabled': True|False,
            'RotationLambdaARN': 'string',
            'RotationRules': {
                'AutomaticallyAfterDays': 123,
                'Duration': 'string',
                'ScheduleExpression': 'string'
            },
            'LastRotatedDate': datetime(2015, 1, 1),
            'LastChangedDate': datetime(2015, 1, 1),
            'LastAccessedDate': datetime(2015, 1, 1),
            'DeletedDate': datetime(2015, 1, 1),
            'NextRotationDate': datetime(2015, 1, 1),
            'Tags': [
                {
                    'Key': 'string',
                    'Value': 'string'
                },
            ],
            'SecretVersionsToStages': {
                'string': [
                    'string',
                ]
            },
            'OwningService': 'string',
            'CreatedDate': datetime(2015, 1, 1),
            'PrimaryRegion': 'string'
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    • SecretList (list) --

      A list of the secrets in the account.

      • (dict) --

        A structure that contains the details about a secret. It does not include the encrypted SecretString and SecretBinary values. To get those values, use GetSecretValue .

        • ARN (string) --

          The Amazon Resource Name (ARN) of the secret.

        • Name (string) --

          The friendly name of the secret. You can use forward slashes in the name to represent a path hierarchy. For example, /prod/databases/dbserver1 could represent the secret for a server named dbserver1 in the folder databases in the folder prod .

        • Description (string) --

          The user-provided description of the secret.

        • KmsKeyId (string) --

          The ARN of the KMS key that Secrets Manager uses to encrypt the secret value. If the secret is encrypted with the Amazon Web Services managed key aws/secretsmanager , this field is omitted.

        • RotationEnabled (boolean) --

          Indicates whether automatic, scheduled rotation is enabled for this secret.

        • RotationLambdaARN (string) --

          The ARN of an Amazon Web Services Lambda function invoked by Secrets Manager to rotate and expire the secret either automatically per the schedule or manually by a call to ` RotateSecret https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_RotateSecret.html`__ .

        • RotationRules (dict) --

          A structure that defines the rotation configuration for the secret.

          • AutomaticallyAfterDays (integer) --

            The number of days between automatic scheduled rotations of the secret. You can use this value to check that your secret meets your compliance guidelines for how often secrets must be rotated.

            In DescribeSecret and ListSecrets , this value is calculated from the rotation schedule after every successful rotation. In RotateSecret , you can set the rotation schedule in RotationRules with AutomaticallyAfterDays or ScheduleExpression , but not both. To set a rotation schedule in hours, use ScheduleExpression .

          • Duration (string) --

            The length of the rotation window in hours, for example 3h for a three hour window. Secrets Manager rotates your secret at any time during this window. The window must not extend into the next rotation window or the next UTC day. The window starts according to the ScheduleExpression . If you don't specify a Duration , for a ScheduleExpression in hours, the window automatically closes after one hour. For a ScheduleExpression in days, the window automatically closes at the end of the UTC day. For more information, including examples, see Schedule expressions in Secrets Manager rotation in the Secrets Manager Users Guide .

          • ScheduleExpression (string) --

            A cron() or rate() expression that defines the schedule for rotating your secret. Secrets Manager rotation schedules use UTC time zone. Secrets Manager rotates your secret any time during a rotation window.

            Secrets Manager rate() expressions represent the interval in hours or days that you want to rotate your secret, for example rate(12 hours) or rate(10 days) . You can rotate a secret as often as every four hours. If you use a rate() expression, the rotation window starts at midnight. For a rate in hours, the default rotation window closes after one hour. For a rate in days, the default rotation window closes at the end of the day. You can set the Duration to change the rotation window. The rotation window must not extend into the next UTC day or into the next rotation window.

            You can use a cron() expression to create a rotation schedule that is more detailed than a rotation interval. For more information, including examples, see Schedule expressions in Secrets Manager rotation in the Secrets Manager Users Guide . For a cron expression that represents a schedule in hours, the default rotation window closes after one hour. For a cron expression that represents a schedule in days, the default rotation window closes at the end of the day. You can set the Duration to change the rotation window. The rotation window must not extend into the next UTC day or into the next rotation window.

        • LastRotatedDate (datetime) --

          The most recent date and time that the Secrets Manager rotation process was successfully completed. This value is null if the secret hasn't ever rotated.

        • LastChangedDate (datetime) --

          The last date and time that this secret was modified in any way.

        • LastAccessedDate (datetime) --

          The date that the secret was last accessed in the Region. This field is omitted if the secret has never been retrieved in the Region.

        • DeletedDate (datetime) --

          The date and time the deletion of the secret occurred. Not present on active secrets. The secret can be recovered until the number of days in the recovery window has passed, as specified in the RecoveryWindowInDays parameter of the ` DeleteSecret https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_DeleteSecret.html`__ operation.

        • NextRotationDate (datetime) --

        • Tags (list) --

          The list of user-defined tags associated with the secret. To add tags to a secret, use ` TagResource https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_TagResource.html`__ . To remove tags, use ` UntagResource https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_UntagResource.html`__ .

          • (dict) --

            A structure that contains information about a tag.

            • Key (string) --

              The key identifier, or name, of the tag.

            • Value (string) --

              The string value associated with the key of the tag.

        • SecretVersionsToStages (dict) --

          A list of all of the currently assigned SecretVersionStage staging labels and the SecretVersionId attached to each one. Staging labels are used to keep track of the different versions during the rotation process.

          Note

          A version that does not have any SecretVersionStage is considered deprecated and subject to deletion. Such versions are not included in this list.

          • (string) --

            • (list) --

              • (string) --

        • OwningService (string) --

          Returns the name of the service that created the secret.

        • CreatedDate (datetime) --

          The date and time when a secret was created.

        • PrimaryRegion (string) --

          The Region where Secrets Manager originated the secret.

    • 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 ListSecrets again with this value.