Reputation: 31
I want to update existing secret's secret string in AWS secrets manager using AWS-SDK for Java. From the example request https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_UpdateSecret.html#API_UpdateSecret_Examples I could figure out that I need to to set SecretId in the com.amazonaws.services.secretsmanager.model.UpdateSecretRequest, but I am confused as I have not provided any SecretId while creating the secret. Is secretId is equivalent to SecretName? Can I set with UpdateSecretRequest.setSecretId("SecertName")? or if there is any other way to get secretId ?
Upvotes: 0
Views: 2727
Reputation: 267
Secret Id refers to the Secret Name. there is nothing called a specific ID for the secret.
SecretId Specifies the secret that you want to modify or to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret.
you can write a sample code like the below to update your existing secret string:
String secretName = "tutorials/MySecondSecretFromProgram";
String secretDescription = "The Secret description I Updated using the AWS Sdk...";
String region = "us-east-2";
BasicAWSCredentials awsCreds = new BasicAWSCredentials("Your_access_key_id", "your_secret-access_key");
AWSSecretsManager client = AWSSecretsManagerClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion (region).build();
UpdateSecretRequest updateSecretRequest = new UpdateSecretRequest ().withSecretId (secretName);
updateSecretRequest.setDescription (secretDescription);
JSONObject secretValues = new JSONObject ();
secretValues.put ("my_secret_label", "My_secret_label_Updated");
secretValues.put ("my_secret-value", "My_secret_value_Updated");
updateSecretRequest.setSecretString (secretValues.toString ());
client.updateSecret(updateSecretRequest);
Upvotes: 1
Reputation: 3
client.updateSecret(updateSecretRequest);
I think you forgot to add this line. You have updated your secret now you need to tell the client to update that.
Upvotes: 0