Append keys to existing Secret in AWS Secrets Manager
The AWS update-secret
operation for Secrets Manager replaces all keys of a secret with the new value provided in the --secret-string
.
But sometimes we want to add a few extra keys, without replacing values already present in a secret.
In this post we show how to use bash to add keys to a secret without replacing existing values.
#
What you need- jq installed
#
1. Prepare the list of secrets you want to add the new keysThis command generates a file named all-secrets
. Run the command and update the file to reflect the list of secrets you want to add the new keys.
Keep only the the secrets you want to add the new keys in the generated
all-secrets
file
new-keys.json
#
2. Store the new keys in a json file named #
3. Run the scriptThe script uses the all-secrets
and new-keys.json
files created in steps 1 and 2.
all-secrets
file, the script:#
For each line in the - Gets current secret value and save to
current-keys.json
file - Merges
current-keys.soj
andnew-keys.json
intomerge.json
- Updates the secret value with the
merge.json
file contents as thesecret-string