Skip to content

Instantly share code, notes, and snippets.

@Antvirf
Created August 28, 2024 04:44
Show Gist options
  • Save Antvirf/6cf15da6575d79587ce4384aae8efdf8 to your computer and use it in GitHub Desktop.
Save Antvirf/6cf15da6575d79587ce4384aae8efdf8 to your computer and use it in GitHub Desktop.
Migrate AWS Systems Manager Parameter Store parameters from one AWS account to another
#!/bin/bash
# You must have configured AWS CLI profiles for both source and target, and have authenticated/refreshed the relevant tokens
OLD_AWS_PROFILE=___
NEW_AWS_PROFILE=___
# Stage 1: Get current list of params names and save them to a file
echo "Fetching parameters list..."
aws ssm describe-parameters --page-size 50 --max-items 1000 | jq -r '.Parameters[].Name' > raw_param_names.txt
# Stage 1b: any additional filtering you want to do, e.g. with grep
cat raw_param_names.txt | grep "docker" > filtered_param_names.txt
while read param; do
echo "Processing parameter: $param"
# Step 1: Get current value from SSM
aws ssm get-parameter --name $param --profile $OLD_AWS_PROFILE --with-decryption | jq >tmp.json
param_value=$(cat tmp.json | jq -r '.Parameter.Value' | tr '\n' ' ')
param_type=$(cat tmp.json | jq -r '.Parameter.Type')
# Step 2: Create in target AWS account
aws ssm put-parameter --name $param --value "$param_value" --type $param_type --profile $NEW_AWS_PROFILE --overwrite
done <filtered_param_names.txt
# Cleanup
rm tmp.json raw_param_names.txt filtered_param_names.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment