updateSecret
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-ecrypt existing secret versions with the new key. For more information, see Secret encryption and decryption.
Samples
fun main() {
//sampleStart
// The following example shows how to modify the description of a secret.
val resp = secretsManagerClient.updateSecret {
secretId = "MyTestDatabaseSecret"
description = "This is a new description for the secret."
clientRequestToken = "EXAMPLE1-90ab-cdef-fedc-ba987EXAMPLE"
}
//sampleEnd
}
fun main() {
//sampleStart
// This example shows how to update the KMS customer managed key (CMK) used to encrypt the secret
// value. The KMS CMK must be in the same region as the secret.
val resp = secretsManagerClient.updateSecret {
secretId = "MyTestDatabaseSecret"
kmsKeyId = "arn:aws:kms:us-west-2:123456789012:key/EXAMPLE2-90ab-cdef-fedc-ba987EXAMPLE"
}
//sampleEnd
}
fun main() {
//sampleStart
// The following example shows how to create a new version of the secret by updating the SecretString
// field. Alternatively, you can use the put secret value operation.
val resp = secretsManagerClient.updateSecret {
secretId = "MyTestDatabaseSecret"
secretString = "{JSON STRING WITH CREDENTIALS}"
}
//sampleEnd
}