[ aws . secretsmanager ]
Configures and starts the asynchronous process of rotating this secret. If you include the configuration parameters, the operation sets those values for the secret and then immediately starts a rotation. If you do not include the configuration parameters, the operation starts a rotation with the values already stored in the secret. After the rotation completes, the protected service and its clients all use the new version of the secret.
This required configuration information includes the ARN of an AWS Lambda function and the time between scheduled rotations. The Lambda rotation function creates a new version of the secret and creates or updates the credentials on the protected service to match. After testing the new credentials, the function marks the new secret with the staging label AWSCURRENT
so that your clients all immediately begin to use the new version. For more information about rotating secrets and how to configure a Lambda function to rotate the secrets for your protected service, see Rotating Secrets in AWS Secrets Manager in the AWS Secrets Manager User Guide .
Secrets Manager schedules the next rotation when the previous one completes. 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.
The rotation function must end with the versions of the secret in one of two states:
The AWSPENDING
and AWSCURRENT
staging labels are attached to the same version of the secret, or
The AWSPENDING
staging label is not attached to any version of the secret.
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.
Minimum permissions
To run this command, you must have the following permissions:
secretsmanager:RotateSecret
lambda:InvokeFunction (on the function specified in the secret’s metadata)
Related operations
To list the secrets in your account, use ListSecrets .
To get the details for a version of a secret, use DescribeSecret .
To create a new version of a secret, use CreateSecret .
To attach staging labels to or remove staging labels from a version of a secret, use UpdateSecretVersionStage .
See also: AWS API Documentation
See ‘aws help’ for descriptions of global parameters.
rotate-secret
--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)
Specifies the secret that you want to rotate. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret.
Note
If you specify an ARN, we generally recommend that you specify a complete ARN. You can specify a partial ARN too—for example, if you don’t include the final hyphen and six random characters that Secrets Manager adds at the end of the ARN when you created the secret. A partial ARN match can work as long as it uniquely matches only one secret. However, if your secret has a name that ends in a hyphen followed by six characters (before Secrets Manager adds the hyphen and six characters to the ARN) and you try to use that as a partial ARN, then those characters cause Secrets Manager to assume that you’re specifying a complete ARN. This confusion can cause unexpected results. To avoid this situation, we recommend that you don’t create secret names ending with a hyphen followed by six characters.
If you specify an incomplete ARN without the random suffix, and instead provide the ‘friendly name’, you must not include the random suffix. If you do include the random suffix added by Secrets Manager, you receive either a ResourceNotFoundException or an AccessDeniedException error, depending on your permissions.
--client-request-token
(string)
(Optional) Specifies a unique identifier for the new version of the secret that helps ensure idempotency.
If you use the AWS CLI or one of the AWS 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 your own value if you implement your own retry logic and want to ensure that a given secret is not created twice. We recommend that you generate a UUID-type value to ensure uniqueness within the specified secret.
Secrets Manager uses this value to prevent the accidental creation of duplicate versions if there are failures and retries during the function’s processing. This value becomes the
VersionId
of the new version.
--rotation-lambda-arn
(string)
(Optional) Specifies the ARN of the Lambda 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:
AutomaticallyAfterDays=long
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.
To configure rotation for a secret
The following example configures rotation for a secret by providing the ARN of a Lambda rotation function (which must already exist) and the number of days between rotation. The first rotation happens immediately upon completion of this command. The rotation function runs asynchronously in the background.
aws secretsmanager rotate-secret --secret-id MyTestDatabaseSecret \
--rotation-lambda-arn arn:aws:lambda:us-west-2:1234566789012:function:MyTestRotationLambda \
--rotation-rules AutomaticallyAfterDays=30
The output shows the following, including the VersionId
of the new secret version:
{
"ARN": "aws:arn:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3",
"Name": "MyTestDatabaseSecret",
"VersionId": "EXAMPLE1-90ab-cdef-fedc-ba987EXAMPLE"
}
To request an immediate rotation for a secret
The following example requests an immediate invocation of the secret’s Lambda rotation function. It assumes that the specified secret already has rotation configured. The rotation function runs asynchronously in the background.
aws secretsmanager rotate-secret --secret-id MyTestDatabaseSecret
The output shows the following, including the VersionId
of the new secret version:
{
"ARN": "aws:arn:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3",
"Name": "MyTestDatabaseSecret",
"VersionId": "EXAMPLE2-90ab-cdef-fedc-ba987EXAMPLE"
}
ARN -> (string)
The ARN of the secret.
Name -> (string)
The friendly name of the secret.
VersionId -> (string)
The ID of the new version of the secret created by the rotation started by this request.