1

I used the code snippet from the post How to update AWS Secrets Manager via python?

But I am running into an issue with the update secret. After execution of the code in the AWS console, I get the below error when I try to retrieve the secret

The secret value can't be converted to key name and value pairs

Code snippet:

updated_secret = original_secret.update({"password":"123admin"}) client.update_secret(SecretId="mysecret", SecretString=json.dumps(updated_secret))
Anton Menshov
  • 2,266
  • 14
  • 34
  • 55
sam
  • 43
  • 1
  • 4

1 Answers1

0

You are trying to retrieve the value from the response syntax.

myrequest={ "ARN": "string", "Name": "string", "VersionId": "string"}

client.update_secret(myrequest)

(maybe I forgot the json dump).

You need two requests: to have first update the value with .update, and then get it with .get

See documentation and the one about update

The proper way to do it is:

{
   "SecretId": "mysecret",
   "SecretString": "admin123"
}
Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
  • aws secretsmanager update-secret --secret-id mysecret --region us-east-1 --secret-string '{"username":"anika","password":"mypwd"}' works fine But if I pass a variable $serverPwd it does not replace the variable serverPwd=mypwd aws secretsmanager update-secret --secret-id mysecret --region us-east-1 --secret-string '{"username":"anika","password":"$serverPwd"} Any thoughts how to pass variable – sam Mar 23 '21 at 01:34