[ aws . secretsmanager ]



Configures and starts the asynchronous process of rotating the secret.

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. For more information about rotation, see Rotate secrets .

To configure rotation, you include the ARN of an Amazon Web Services Lambda function and the schedule for the rotation. The Lambda rotation function creates a new version of the secret and creates or updates the credentials on the database or service to match. After testing the new credentials, the function marks the new secret version with the staging label AWSCURRENT . Then anyone who retrieves the secret gets the new version. For more information, see How rotation works .

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.

To run this command, you must have secretsmanager:RotateSecret permissions and lambda:InvokeFunction permissions on the function specified in the secret’s metadata.

See also: AWS API Documentation

See ‘aws help’ for descriptions of global parameters.


--secret-id <value>
[--client-request-token <value>]
[--rotation-lambda-arn <value>]
[--rotation-rules <value>]
[--cli-input-json | --cli-input-yaml]
[--generate-cli-skeleton <value>]


--secret-id (string)

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.

--client-request-token (string)

A unique identifier for the new version of the secret that helps ensure idempotency. Secrets Manager uses this value to prevent the accidental creation of duplicate versions if there are failures and retries during rotation. This value becomes the VersionId of the new version.

If you use the Amazon Web Services CLI or one of the Amazon Web Services SDK to call this operation, then you can leave this parameter empty. The CLI or SDK generates a random UUID for you and includes that in the request for this parameter. If you don’t use the SDK and instead generate a raw HTTP request to the Secrets Manager service endpoint, then you must generate a ClientRequestToken yourself for new versions and include that value in the request.

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. We recommend that you generate a UUID-type value to ensure uniqueness within the specified secret.

--rotation-lambda-arn (string)

The ARN of the Lambda rotation function that can rotate the secret.

--rotation-rules (structure)

A structure that defines the rotation configuration for this secret.

AutomaticallyAfterDays -> (long)

Specifies the number of days between automatic scheduled rotations of the secret.

Secrets Manager schedules the next rotation when the previous one is complete. Secrets Manager schedules the date by adding the rotation interval (number of days) to the actual date of the last rotation. The service chooses the hour within that 24-hour date window randomly. The minute is also chosen somewhat randomly, but weighted towards the top of the hour and influenced by a variety of factors that help distribute load.

Shorthand Syntax:


JSON Syntax:

  "AutomaticallyAfterDays": long

--cli-input-json | --cli-input-yaml (string) Reads arguments from the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton. If other arguments are provided on the command line, those values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally. This may not be specified along with --cli-input-yaml.

--generate-cli-skeleton (string) Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. Similarly, if provided yaml-input it will print a sample input YAML that can be used with --cli-input-yaml. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.

See ‘aws help’ for descriptions of global parameters.


Example 1: To configure and start automatic rotation for a secret

The following rotate-secret example configures and starts automatic rotation for a secret. Secrets Manager rotates the secret once immediately and then automatically every 10 days. The output shows the VersionId of the new secret version created by rotation.

aws secretsmanager rotate-secret \
    --secret-id MyTestDatabaseSecret \
    --rotation-lambda-arn arn:aws:lambda:us-west-2:1234566789012:function:SecretsManagerTestRotationLambda \
    --rotation-rules AutomaticallyAfterDays=10


    "ARN": "aws:arn:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3",
    "Name": "MyTestDatabaseSecret",
    "VersionId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"

For more information, see This is the topic title in the Secrets Manager User Guide.

Example 2: To rotate a secret immediately

The following rotate-secret example starts an immediate rotation. The output shows the VersionId of the new secret version created by rotation. The secret must already have rotation configured.

aws secretsmanager rotate-secret \
    --secret-id MyTestDatabaseSecret


    "ARN": "aws:arn:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3",
    "Name": "MyTestDatabaseSecret",
    "VersionId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"

For more information, see Rotate secrets in the Secrets Manager User Guide.


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.