Skip to content

Instantly share code, notes, and snippets.

@srkiNZ84
Created September 22, 2020 03:12
Show Gist options
  • Save srkiNZ84/7b6773aa782dc364cd95c7b775824dcd to your computer and use it in GitHub Desktop.
Save srkiNZ84/7b6773aa782dc364cd95c7b775824dcd to your computer and use it in GitHub Desktop.
Copy SSM parameters from one path in SSM to another
#!/usr/bin/python3
import boto3
session = boto3.Session(profile_name='foobar')
client = session.client('ssm')
fromPath = "/production/"
toPath = "/uat/"
moreParamsToCome = True
nextToken = ""
while(moreParamsToCome):
response = {}
if nextToken:
print("Non empty next token")
response = client.get_parameters_by_path(
Path=fromPath,
Recursive=True,
WithDecryption=True,
NextToken=nextToken
)
else:
print("Empty next token")
response = client.get_parameters_by_path(
Path=fromPath,
Recursive=True,
WithDecryption=True,
)
for param in response['Parameters']:
print("Param: " + param['Name'] + " is set to: " + param['Value'] + "\n")
print("Ater path is: " + param["Name"].split(fromPath)[1])
print("Putting new parameter in")
putResponse = client.put_parameter(Type=param['Type'], Name=toPath + param['Name'].split(fromPath)[1], Overwrite=True, Value=param['Value'])
if 'NextToken' in response:
#print("Got Next token: " + response['NextToken'])
nextToken = response['NextToken']
moreParamsToCome = True
else:
print("No more params")
moreParamsToCome = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment