Skip to content

Instantly share code, notes, and snippets.

@skwashd skwashd/
Last active Jul 1, 2020

What would you like to do?
Copy AWS SSM Parameter Store Path

This Python (3.6+) script is for migrating Amazon AWS System Manager (SSM) Parameter Store keys from one path to another.

Quick Start

To install the script do the following:

  • Configure your AWS credentials
  • Grab the code from this gist
  • Make it executable (chmod +x /path/to/
  • pip install boto3 (if you don't have it installed already)

Run it like so: source-tree-name target-tree-name new-kms-uuid

More information

For more information about this script checkout my blog post Migrating AWS System Manager Parameter Store Secrets to a new Namespace.

#!/usr/bin/env python3
# Copy SSM Parameter Store values to a new path.
# Designed to work with Python 3.6 and up. Only external dependency is boto3.
# Call: source-tree-name target-tree-name new-kms-uuid
import os
import sys
import boto3
def main(args):
if len(args) != 4:
sys.stderr.write("Invalid args.\n")
source_path = args[1]
target_path = args[2]
key_alias = args[3]
ssm = boto3.client("ssm")
paginator = ssm.get_paginator("get_parameters_by_path")
for page in paginator.paginate(Path=f"/{source_path}/", WithDecryption=True):
for parameter in page["Parameters"]:
raw_key = parameter["Name"]
key_name = os.path.basename(raw_key)
new_name = f"/{target_path}/{key_name}"
sys.stderr.write(f"Copied {key_name} from {source_path} to {target_path}.\n")
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.