AWS Secrets Manager

2025/11/19 - AWS Secrets Manager - 5 updated api methods

Changes  Adds support to create, update, retrieve, rotate, and delete managed external secrets.

CreateSecret (updated) Link ¶
Changes (request)
{'Type': 'string'}

Creates a new secret. A secret can be a password, a set of credentials such as a user name and password, an OAuth token, or other secret information that you store in an encrypted form in Secrets Manager. The secret also includes the connection information to access a database or other service, which Secrets Manager doesn't encrypt. A secret in Secrets Manager consists of both the protected secret data and the important information needed to manage the secret.

For secrets that use managed rotation, you need to create the secret through the managing service. For more information, see Secrets Manager secrets managed by other Amazon Web Services services.

For information about creating a secret in the console, see Create a secret.

To create a secret, you can provide the secret value to be encrypted in either the SecretString parameter or the SecretBinary parameter, but not both. If you include SecretString or SecretBinary then Secrets Manager creates an initial secret version and automatically attaches the staging label AWSCURRENT to it.

For database credentials you want to rotate, for Secrets Manager to be able to rotate the secret, you must make sure the JSON you store in the SecretString matches the JSON structure of a database secret.

If you don't specify an KMS encryption key, Secrets Manager uses the Amazon Web Services managed key aws/secretsmanager. If this key doesn't already exist in your account, then Secrets Manager creates it for you automatically. All users and roles in the Amazon Web Services account automatically have access to use aws/secretsmanager. Creating aws/secretsmanager can result in a one-time significant delay in returning the result.

If the secret is in a different Amazon Web Services account from the credentials calling the API, then you can't use aws/secretsmanager to encrypt the secret, and you must create and use a customer managed KMS key.

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

Required permissions: secretsmanager:CreateSecret. If you include tags in the secret, you also need secretsmanager:TagResource. To add replica Regions, you must also have secretsmanager:ReplicateSecretToRegions. For more information, see IAM policy actions for Secrets Manager and Authentication and access control in Secrets Manager.

To encrypt the secret with a KMS key other than aws/secretsmanager, you need kms:GenerateDataKey and kms:Decrypt permission to the key.

See also: AWS API Documentation

Request Syntax

client.create_secret(
    Name='string',
    ClientRequestToken='string',
    Description='string',
    KmsKeyId='string',
    SecretBinary=b'bytes',
    SecretString='string',
    Tags=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ],
    AddReplicaRegions=[
        {
            'Region': 'string',
            'KmsKeyId': 'string'
        },
    ],
    ForceOverwriteReplicaSecret=True|False,
    Type='string'
)
type Name:

string

param Name:

[REQUIRED]

The name of the new secret.

The secret name can contain ASCII letters, numbers, and the following characters: /_+=.@-

Do not end your secret name with a hyphen followed by six characters. If you do so, you risk confusion and unexpected results when searching for a secret by partial ARN. Secrets Manager automatically adds a hyphen and six random characters after the secret name at the end of the ARN.

type ClientRequestToken:

string

param ClientRequestToken:

If you include SecretString or SecretBinary, then Secrets Manager creates an initial version for the secret, and this parameter specifies the unique identifier for the new version.

If you generate a raw HTTP request to the Secrets Manager service endpoint, then you must generate a ClientRequestToken and include it in the request.

This value helps ensure idempotency. Secrets Manager uses this value to prevent the accidental creation of duplicate versions if there are failures and retries during a rotation. We recommend that you generate a UUID-type value to ensure uniqueness of your versions within the specified secret.

  • If the ClientRequestToken value isn't already associated with a version of the secret then a new version of the secret is created.

  • If a version with this value already exists and the version SecretString and SecretBinary values are the same as those in the request, then the request is ignored.

  • If a version with this value already exists and that version's SecretString and SecretBinary values are different from those in the request, then the request fails because you cannot modify an existing version. Instead, use PutSecretValue to create a new version.

This value becomes the VersionId of the new version.

This field is autopopulated if not provided.

type Description:

string

param Description:

The description of the secret.

type KmsKeyId:

string

param KmsKeyId:

The ARN, key ID, or alias of the KMS key that Secrets Manager uses to encrypt the secret value in the secret. An alias is always prefixed by alias/, for example alias/aws/secretsmanager. For more information, see About aliases.

To use a KMS key in a different account, use the key ARN or the alias ARN.

If you don't specify this value, then Secrets Manager uses the key aws/secretsmanager. If that key doesn't yet exist, then Secrets Manager creates it for you automatically the first time it encrypts the secret value.

If the secret is in a different Amazon Web Services account from the credentials calling the API, then you can't use aws/secretsmanager to encrypt the secret, and you must create and use a customer managed KMS key.

type SecretBinary:

bytes

param SecretBinary:

The binary data to encrypt and store in the new version of the secret. We recommend that you store your binary data in a file and then pass the contents of the file as a parameter.

Either SecretString or SecretBinary must have a value, but not both.

This parameter is not available in the Secrets Manager console.

Sensitive: This field contains sensitive information, so the service does not include it in CloudTrail log entries. If you create your own log entries, you must also avoid logging the information in this field.

type SecretString:

string

param SecretString:

The text data to encrypt and store in this new version of the secret. We recommend you use a JSON structure of key/value pairs for your secret value.

Either SecretString or SecretBinary must have a value, but not both.

If you create a secret by using the Secrets Manager console then Secrets Manager puts the protected secret text in only the SecretString parameter. The Secrets Manager console stores the information as a JSON structure of key/value pairs that a Lambda rotation function can parse.

Sensitive: This field contains sensitive information, so the service does not include it in CloudTrail log entries. If you create your own log entries, you must also avoid logging the information in this field.

type Tags:

list

param Tags:

A list of tags to attach to the secret. Each tag is a key and value pair of strings in a JSON text string, for example:

[{"Key":"CostCenter","Value":"12345"},{"Key":"environment","Value":"production"}]

Secrets Manager tag key names are case sensitive. A tag with the key "ABC" is a different tag from one with key "abc".

If you check tags in permissions policies as part of your security strategy, then adding or removing a tag can change permissions. If the completion of this operation would result in you losing your permissions for this secret, then Secrets Manager blocks the operation and returns an Access Denied error. For more information, see Control access to secrets using tags and Limit access to identities with tags that match secrets' tags.

For information about how to format a JSON parameter for the various command line tool environments, see Using JSON for Parameters. If your command-line tool or SDK requires quotation marks around the parameter, you should use single quotes to avoid confusion with the double quotes required in the JSON text.

For tag quotas and naming restrictions, see Service quotas for Tagging in the Amazon Web Services General Reference guide.

  • (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.

type AddReplicaRegions:

list

param AddReplicaRegions:

A list of Regions and KMS keys to replicate secrets.

  • (dict) --

    A custom type that specifies a Region and the KmsKeyId for a replica secret.

    • Region (string) --

      A Region code. For a list of Region codes, see Name and code of Regions.

    • KmsKeyId (string) --

      The ARN, key ID, or alias of the KMS key to encrypt the secret. If you don't include this field, Secrets Manager uses aws/secretsmanager.

type ForceOverwriteReplicaSecret:

boolean

param ForceOverwriteReplicaSecret:

Specifies whether to overwrite a secret with the same name in the destination Region. By default, secrets aren't overwritten.

type Type:

string

param Type:

The exact string that identifies the partner that holds the external secret. For more information, see Using Secrets Manager managed external secrets.

rtype:

dict

returns:

Response Syntax

{
    'ARN': 'string',
    'Name': 'string',
    'VersionId': '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 new secret. The ARN includes the name of the secret followed by six random characters. This ensures that if you create a new secret with the same name as a deleted secret, then users with access to the old secret don't get access to the new secret because the ARNs are different.

    • Name (string) --

      The name of the new secret.

    • VersionId (string) --

      The unique identifier associated with the version of the new secret.

    • 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.

DescribeSecret (updated) Link ¶
Changes (response)
{'ExternalSecretRotationMetadata': [{'Key': 'string', 'Value': 'string'}],
 'ExternalSecretRotationRoleArn': 'string',
 'Type': 'string'}

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',
    'Type': 'string',
    'Description': 'string',
    'KmsKeyId': 'string',
    'RotationEnabled': True|False,
    'RotationLambdaARN': 'string',
    'RotationRules': {
        'AutomaticallyAfterDays': 123,
        'Duration': 'string',
        'ScheduleExpression': 'string'
    },
    'ExternalSecretRotationMetadata': [
        {
            'Key': 'string',
            'Value': 'string'
        },
    ],
    'ExternalSecretRotationRoleArn': '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.

    • Type (string) --

      The exact string that identifies the partner that holds the external secret. For more information, see Using Secrets Manager managed external secrets.

    • 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. If the secret has never been configured for rotation, Secrets Manager returns null.

      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 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. If you use this field to set the rotation schedule, Secrets Manager calculates the next rotation date based on the previous rotation. Manually updating the secret value by calling PutSecretValue or UpdateSecret is considered a valid rotation.

        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.

    • ExternalSecretRotationMetadata (list) --

      The metadata needed to successfully rotate a managed external secret. A list of key value pairs in JSON format specified by the partner. For more information about the required information, see Managed external secrets partners.

      • (dict) --

        The metadata needed to successfully rotate a managed external secret. A list of key value pairs in JSON format specified by the partner. For more information, see Managed external secret partners.

        • Key (string) --

          The key that identifies the item.

        • Value (string) --

          The value of the specified item.

    • ExternalSecretRotationRoleArn (string) --

      The Amazon Resource Name (ARN) of the role that allows Secrets Manager to rotate a secret held by a third-party partner. For more information, see Security and permissions.

    • LastRotatedDate (datetime) --

      The last date and time that Secrets Manager rotated the secret. If the secret isn't configured for rotation or rotation has been disabled, 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) --

      The next rotation is scheduled to occur on or before this date. If the secret isn't configured for rotation or rotation has been disabled, Secrets Manager returns null. If rotation fails, Secrets Manager retries the entire rotation process multiple times. If rotation is unsuccessful, this date may be in the past.

      This date represents the latest date that rotation will occur, but it is not an approximate rotation date. In some cases, for example if you turn off automatic rotation and then turn it back on, the next rotation may occur much sooner than this date.

    • 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 (response)
{'SecretList': {'ExternalSecretRotationMetadata': [{'Key': 'string',
                                                    'Value': 'string'}],
                'ExternalSecretRotationRoleArn': 'string',
                'Type': 'string'}}

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.

All Secrets Manager operations are eventually consistent. ListSecrets might not reflect changes from the last five minutes. You can get more recent information for a specific secret by calling DescribeSecret.

To list the versions of a secret, use ListSecretVersionIds.

To retrieve the values for the secrets, call BatchGetSecretValue or 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:

Specifies whether to include secrets scheduled for deletion. By default, secrets scheduled for deletion aren't included.

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.

      • owning-service: 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',
            'Type': 'string',
            'Description': 'string',
            'KmsKeyId': 'string',
            'RotationEnabled': True|False,
            'RotationLambdaARN': 'string',
            'RotationRules': {
                'AutomaticallyAfterDays': 123,
                'Duration': 'string',
                'ScheduleExpression': 'string'
            },
            'ExternalSecretRotationMetadata': [
                {
                    'Key': 'string',
                    'Value': 'string'
                },
            ],
            'ExternalSecretRotationRoleArn': '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.

        • Type (string) --

          The exact string that identifies the third-party partner that holds the external secret. For more information, see Managed external secret partners.

        • 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.

        • RotationRules (dict) --

          A structure that defines the rotation configuration for the secret.

          • AutomaticallyAfterDays (integer) --

            The number of days between 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. If you use this field to set the rotation schedule, Secrets Manager calculates the next rotation date based on the previous rotation. Manually updating the secret value by calling PutSecretValue or UpdateSecret is considered a valid rotation.

            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.

        • ExternalSecretRotationMetadata (list) --

          The metadata needed to successfully rotate a managed external secret. A list of key value pairs in JSON format specified by the partner. For more information about the required information, see Managed external secrets partners.

          • (dict) --

            The metadata needed to successfully rotate a managed external secret. A list of key value pairs in JSON format specified by the partner. For more information, see Managed external secret partners.

            • Key (string) --

              The key that identifies the item.

            • Value (string) --

              The value of the specified item.

        • ExternalSecretRotationRoleArn (string) --

          The role that Secrets Manager assumes to call APIs required to perform the rotation. For more information about the required information, see Managed external secrets partners.

        • 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 operation.

        • NextRotationDate (datetime) --

          The next rotation is scheduled to occur on or before this date. If the secret isn't configured for rotation or rotation has been disabled, Secrets Manager returns null.

        • Tags (list) --

          The list of user-defined tags associated with 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.

        • 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.

          • (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.

RotateSecret (updated) Link ¶
Changes (request)
{'ExternalSecretRotationMetadata': [{'Key': 'string', 'Value': 'string'}],
 'ExternalSecretRotationRoleArn': 'string'}

Configures and starts the asynchronous process of rotating the secret. For information about rotation, see Rotate secrets in the Secrets Manager User Guide. If you include the configuration parameters, the operation sets the values for the secret and then immediately starts a rotation. If you don't include the configuration parameters, the operation starts a rotation with the values already stored in the secret.

When rotation is successful, the AWSPENDING staging label might be attached to the same version as the AWSCURRENT version, or it might not be attached to any version. If the AWSPENDING staging label is present but not attached to the same version as AWSCURRENT, then any later invocation of RotateSecret assumes that a previous rotation request is still in progress and returns an error. When rotation is unsuccessful, the AWSPENDING staging label might be attached to an empty secret version. For more information, see Troubleshoot rotation in the Secrets Manager User Guide.

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:RotateSecret. For more information, see IAM policy actions for Secrets Manager and Authentication and access control in Secrets Manager. You also need lambda:InvokeFunction permissions on the rotation function. For more information, see Permissions for rotation.

See also: AWS API Documentation

Request Syntax

client.rotate_secret(
    SecretId='string',
    ClientRequestToken='string',
    RotationLambdaARN='string',
    RotationRules={
        'AutomaticallyAfterDays': 123,
        'Duration': 'string',
        'ScheduleExpression': 'string'
    },
    ExternalSecretRotationMetadata=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ],
    ExternalSecretRotationRoleArn='string',
    RotateImmediately=True|False
)
type SecretId:

string

param SecretId:

[REQUIRED]

The ARN or name of the secret to rotate.

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

type ClientRequestToken:

string

param ClientRequestToken:

A unique identifier for the new version of the secret. You only need to specify this value if you implement your own retry logic and you want to ensure that Secrets Manager doesn't attempt to create a secret version twice.

If you generate a raw HTTP request to the Secrets Manager service endpoint, then you must generate a ClientRequestToken and include it in the request.

This value helps ensure idempotency. Secrets Manager uses this value to prevent the accidental creation of duplicate versions if there are failures and retries during a rotation. We recommend that you generate a UUID-type value to ensure uniqueness of your versions within the specified secret.

This field is autopopulated if not provided.

type RotationLambdaARN:

string

param RotationLambdaARN:

For secrets that use a Lambda rotation function to rotate, the ARN of the Lambda rotation function.

For secrets that use managed rotation, omit this field. For more information, see Managed rotation in the Secrets Manager User Guide.

type RotationRules:

dict

param RotationRules:

A structure that defines the rotation configuration for this secret.

  • AutomaticallyAfterDays (integer) --

    The number of days between 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. If you use this field to set the rotation schedule, Secrets Manager calculates the next rotation date based on the previous rotation. Manually updating the secret value by calling PutSecretValue or UpdateSecret is considered a valid rotation.

    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.

type ExternalSecretRotationMetadata:

list

param ExternalSecretRotationMetadata:

The metadata needed to successfully rotate a managed external secret. A list of key value pairs in JSON format specified by the partner. For more information about the required information, see Using Secrets Manager managed external secrets

  • (dict) --

    The metadata needed to successfully rotate a managed external secret. A list of key value pairs in JSON format specified by the partner. For more information, see Managed external secret partners.

    • Key (string) --

      The key that identifies the item.

    • Value (string) --

      The value of the specified item.

type ExternalSecretRotationRoleArn:

string

param ExternalSecretRotationRoleArn:

The Amazon Resource Name (ARN) of the role that allows Secrets Manager to rotate a secret held by a third-party partner. For more information, see Security and permissions.

type RotateImmediately:

boolean

param RotateImmediately:

Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. The rotation schedule is defined in RotateSecretRequest$RotationRules.

The default for RotateImmediately is true. If you don't specify this value, Secrets Manager rotates the secret immediately.

If you set RotateImmediately to false, Secrets Manager tests the rotation configuration by running the testSecret step of the Lambda rotation function. This test creates an AWSPENDING version of the secret and then removes it.

When changing an existing rotation schedule and setting RotateImmediately to false:

  • If using AutomaticallyAfterDays or a ScheduleExpression with rate(), the previously scheduled rotation might still occur.

  • To prevent unintended rotations, use a ScheduleExpression with cron() for granular control over rotation windows.

Rotation is an asynchronous process. For more information, see How rotation works.

rtype:

dict

returns:

Response Syntax

{
    'ARN': 'string',
    'Name': 'string',
    'VersionId': 'string'
}

Response Structure

  • (dict) --

    • ARN (string) --

      The ARN of the secret.

    • Name (string) --

      The name of the secret.

    • VersionId (string) --

      The ID of the new version of the secret.

UpdateSecret (updated) Link ¶
Changes (request)
{'Type': 'string'}

Modifies the details of a secret, including metadata and the secret value. To change the secret value, you can also use PutSecretValue.

To change the rotation configuration of a secret, use RotateSecret instead.

To change a secret so that it is managed by another service, you need to recreate the secret in that service. See Secrets Manager secrets managed by other Amazon Web Services services.

We recommend you avoid calling UpdateSecret at a sustained rate of more than once every 10 minutes. When you call UpdateSecret to update the secret value, Secrets Manager creates a new version of the secret. Secrets Manager removes outdated versions when there are more than 100, but it does not remove versions created less than 24 hours ago. If you update the secret value more than once every 10 minutes, you create more versions than Secrets Manager removes, and you will reach the quota for secret versions.

If you include SecretString or SecretBinary to create a new secret version, Secrets Manager automatically moves the staging label AWSCURRENT to the new version. Then it attaches the label AWSPREVIOUS to the version that AWSCURRENT was removed from.

If you call this operation with a ClientRequestToken that matches an existing version's VersionId, the operation results in an error. You can't modify an existing version, you can only create a new version. To remove a version, remove all staging labels from it. See UpdateSecretVersionStage.

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

Required permissions: secretsmanager:UpdateSecret. For more information, see IAM policy actions for Secrets Manager and Authentication and access control in Secrets Manager. If you use a customer managed key, you must also have kms:GenerateDataKey, kms:Encrypt, and kms:Decrypt permissions on the key. If you change the KMS key and you don't have kms:Encrypt permission to the new key, Secrets Manager does not re-encrypt existing secret versions with the new key. For more information, see Secret encryption and decryption.

See also: AWS API Documentation

Request Syntax

client.update_secret(
    SecretId='string',
    ClientRequestToken='string',
    Description='string',
    KmsKeyId='string',
    SecretBinary=b'bytes',
    SecretString='string',
    Type='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.

type ClientRequestToken:

string

param ClientRequestToken:

If you include SecretString or SecretBinary, then Secrets Manager creates a new version for the secret, and this parameter specifies the unique identifier for the new version.

If you generate a raw HTTP request to the Secrets Manager service endpoint, then you must generate a ClientRequestToken and include it in the request.

This value helps ensure idempotency. Secrets Manager uses this value to prevent the accidental creation of duplicate versions if there are failures and retries during a rotation. We recommend that you generate a UUID-type value to ensure uniqueness of your versions within the specified secret.

This field is autopopulated if not provided.

type Description:

string

param Description:

The description of the secret.

type KmsKeyId:

string

param KmsKeyId:

The ARN, key ID, or alias of the KMS key that Secrets Manager uses to encrypt new secret versions as well as any existing versions with the staging labels AWSCURRENT, AWSPENDING, or AWSPREVIOUS. If you don't have kms:Encrypt permission to the new key, Secrets Manager does not re-encrypt existing secret versions with the new key. For more information about versions and staging labels, see Concepts: Version.

A key alias is always prefixed by alias/, for example alias/aws/secretsmanager. For more information, see About aliases.

If you set this to an empty string, Secrets Manager uses the Amazon Web Services managed key aws/secretsmanager. If this key doesn't already exist in your account, then Secrets Manager creates it for you automatically. All users and roles in the Amazon Web Services account automatically have access to use aws/secretsmanager. Creating aws/secretsmanager can result in a one-time significant delay in returning the result.

type SecretBinary:

bytes

param SecretBinary:

The binary data to encrypt and store in the new version of the secret. We recommend that you store your binary data in a file and then pass the contents of the file as a parameter.

Either SecretBinary or SecretString must have a value, but not both.

You can't access this parameter in the Secrets Manager console.

Sensitive: This field contains sensitive information, so the service does not include it in CloudTrail log entries. If you create your own log entries, you must also avoid logging the information in this field.

type SecretString:

string

param SecretString:

The text data to encrypt and store in the new version of the secret. We recommend you use a JSON structure of key/value pairs for your secret value.

Either SecretBinary or SecretString must have a value, but not both.

Sensitive: This field contains sensitive information, so the service does not include it in CloudTrail log entries. If you create your own log entries, you must also avoid logging the information in this field.

type Type:

string

param Type:

The exact string that identifies the third-party partner that holds the external secret. For more information, see Managed external secret partners.

rtype:

dict

returns:

Response Syntax

{
    'ARN': 'string',
    'Name': 'string',
    'VersionId': 'string'
}

Response Structure

  • (dict) --

    • ARN (string) --

      The ARN of the secret that was updated.

    • Name (string) --

      The name of the secret that was updated.

    • VersionId (string) --

      If Secrets Manager created a new version of the secret during this operation, then VersionId contains the unique identifier of the new version.