AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Creates a new version with a new encrypted secret value and attaches it to the secret. The version can contain a new SecretString value or a new SecretBinary value.

We recommend you avoid calling PutSecretValue at a sustained rate of more than once every 10 minutes. When you 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 call PutSecretValue more than once every 10 minutes, you create more versions than Secrets Manager removes, and you will reach the quota for secret versions.

You can specify the staging labels to attach to the new version in VersionStages. If you don't include VersionStages, then Secrets Manager automatically moves the staging label AWSCURRENT to this version. If this operation creates the first version for the secret, then Secrets Manager automatically attaches the staging label AWSCURRENT to it. If this operation moves the staging label AWSCURRENT from another version to this version, then Secrets Manager also automatically moves the staging label AWSPREVIOUS to the version that AWSCURRENT was removed from.

This operation is idempotent. If you call this operation with a ClientRequestToken that matches an existing version's VersionId, and you specify the same secret data, the operation succeeds but does nothing. However, if the secret data is different, then the operation fails because you can't modify an existing version; you can only create new ones.

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

Required permissions: secretsmanager:PutSecretValue. For more information, see IAM policy actions for Secrets Manager and Authentication and access control in Secrets Manager.


For .NET Core this operation is only available in asynchronous form. Please refer to PutSecretValueAsync.

Namespace: Amazon.SecretsManager
Assembly: AWSSDK.SecretsManager.dll
Version: 3.x.y.z


public virtual PutSecretValueResponse PutSecretValue(
         PutSecretValueRequest request


Type: Amazon.SecretsManager.Model.PutSecretValueRequest

Container for the necessary parameters to execute the PutSecretValue service method.

Return Value

The response from the PutSecretValue service method, as returned by SecretsManager.


DecryptionFailureException Secrets Manager can't decrypt the protected secret text using the provided KMS key.
EncryptionFailureException Secrets Manager can't encrypt the protected secret text using the provided KMS key. Check that the KMS key is available, enabled, and not in an invalid state. For more information, see Key state: Effect on your KMS key.
InternalServiceErrorException An error occurred on the server side.
InvalidParameterException The parameter name or value is invalid.
InvalidRequestException A parameter value is not valid for the current state of the resource. Possible causes: The secret is scheduled for deletion. You tried to enable rotation on a secret that doesn't already have a Lambda function ARN configured and you didn't include such an ARN as a parameter in this call. The secret is managed by another service, and you must use that service to update it. For more information, see Secrets managed by other Amazon Web Services services.
LimitExceededException The request failed because it would exceed one of the Secrets Manager quotas.
ResourceExistsException A resource with the ID you requested already exists.
ResourceNotFoundException Secrets Manager can't find the resource that you asked for.


The following example shows how to create a new version of the secret. Alternatively, you can use the update-secret command.

To store a secret value in a new version of a secret

var client = new AmazonSecretsManagerClient();
var response = client.PutSecretValue(new PutSecretValueRequest 
    ClientRequestToken = "EXAMPLE2-90ab-cdef-fedc-ba987EXAMPLE",
    SecretId = "MyTestDatabaseSecret",
    SecretString = "{\"username\":\"david\",\"password\":\"EXAMPLE-PASSWORD\"}"

string arn = response.ARN;
string name = response.Name;
string versionId = response.VersionId;
List<string> versionStages = response.VersionStages;


Version Information

.NET Framework:
Supported in: 4.5 and newer, 3.5

See Also