[ aws . secretsmanager ]

rotate-secret

Description

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.

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

See ‘aws help’ for descriptions of global parameters.

Synopsis

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

Options

--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)

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.

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 go into the next UTC day. If you don’t specify this value, the window automatically ends at the end of the UTC day. The window begins according to the ScheduleExpression . For more information, including examples, see Schedule expressions in Secrets Manager rotation .

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 rate() expressions represent the interval in days that you want to rotate your secret, for example rate(10 days) . If you use a rate() expression, the rotation window opens at midnight, and Secrets Manager rotates your secret any time that day after midnight. You can set a Duration to shorten the rotation window.

You can use a cron() expression to create rotation schedules that are more detailed than a rotation interval. For more information, including examples, see Schedule expressions in Secrets Manager rotation . If you use a cron() expression, Secrets Manager rotates your secret any time during that day after the window opens. For example, cron(0 8 1 * ? *) represents a rotation window that occurs on the first day of every month beginning at 8:00 AM UTC. Secrets Manager rotates the secret any time that day after 8:00 AM. You can set a Duration to shorten the rotation window.

Shorthand Syntax:

AutomaticallyAfterDays=long,Duration=string,ScheduleExpression=string

JSON Syntax:

{
  "AutomaticallyAfterDays": long,
  "Duration": "string",
  "ScheduleExpression": "string"
}

--rotate-immediately | --no-rotate-immediately (boolean)

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

If you don’t immediately rotate the secret, Secrets Manager tests the rotation configuration by running the ` testSecret step <https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_how.html>`__ of the Lambda rotation function. The test creates an AWSPENDING version of the secret and then removes it.

If you don’t specify this value, then by default, Secrets Manager rotates the secret immediately.

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

Examples

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

Output:

{
    "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

Output:

{
    "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.

Output

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.