Skip to content

Instantly share code, notes, and snippets.

@mjsqu
Last active March 16, 2025 21:25
Show Gist options
  • Select an option

  • Save mjsqu/77adb32635c9456a5bfd079a662e929f to your computer and use it in GitHub Desktop.

Select an option

Save mjsqu/77adb32635c9456a5bfd079a662e929f to your computer and use it in GitHub Desktop.
AWS SSM Parameter Store Copy
#!/bin/bash
parameter_name=$1
new_parameter_name=$2
ssmget=$(aws ssm get-parameter --name $1 --with-decryption)
ssmdesc=$(aws ssm describe-parameters --filter Key=Name,Values=$1)
ssmtags=$(aws ssm list-tags-for-resource --resource-type Parameter --resource-id $1)
value=$(echo "$ssmget" | jq -r '.Parameter.Value')
desc=$(echo "$ssmdesc" | jq -r '.Parameters[0].Description')
keyid=$(echo "$ssmdesc" | jq -r '.Parameters[0].KeyId')
aws ssm put-parameter --name $2 --value "${value}" --description "${desc}" --type SecureString --key-id ${keyid} --overwrite
echo "$ssmtags" | jq -r '.TagList[] | "Key=\(.Key),Value=\(.Value)"' | while read x
do
aws ssm add-tags-to-resource --resource-type Parameter --resource-id $2 --tags $x
done
@mjsqu
Copy link
Author

mjsqu commented Mar 16, 2025

The AWS CLI doesn't have a native approach to copying SSM Parameters (as far as I can tell at the time of writing). This gist copies "SecureString" parameters from one parm to another, keeping:

@mjsqu
Copy link
Author

mjsqu commented Mar 16, 2025

⚠️ Disclaimer: No overwrite protection - if the target parameter exists it will be overwritten ⚠️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment