Created
July 2, 2018 01:56
-
-
Save toshke/bad7ee0746d00f22fafc4a880557d33d to your computer and use it in GitHub Desktop.
Copy AWS System Manager Parameters from one path to another path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3; | |
client = boto3.client('ssm') | |
src_path = '/source/ssm/path' | |
dst_path = '/destination/ssm/path' | |
ssm_key_id = '<<keyidhere>>' | |
def printparams(params): | |
for p in params['Parameters']: | |
new_path = p['Name'].replace(src_path, dst_path) | |
print(f"Would put {p['Value']} to {new_path}") | |
# if 'KeyId' in p: | |
print(f"Type={p['Type']}") | |
def putparams(params): | |
for p in params['Parameters']: | |
new_path = p['Name'].replace(src_path, dst_path) | |
if p['Type'] == 'SecureString': | |
client.put_parameter(Name=new_path, | |
Value=p['Value'], | |
Type=p['Type'], | |
KeyId=ssm_key_id | |
) | |
print(f"Saved **** to {new_path}") | |
else: | |
client.put_parameter(Name=new_path, | |
Value=p['Value'], | |
Type=p['Type'] | |
) | |
print(f"Saved {p['Value']} to {new_path}") | |
c = True | |
token = None | |
params = client.get_parameters_by_path(Path=src_path, | |
Recursive=True, | |
WithDecryption=True, | |
MaxResults=10) | |
if 'NextToken' in params: | |
token = params['NextToken'] | |
else: | |
token = None | |
putparams(params) | |
while token is not None: | |
params = client.get_parameters_by_path(Path=src_path, | |
Recursive=True, | |
WithDecryption=True, | |
MaxResults=10, | |
NextToken=token) | |
if 'NextToken' in params: | |
token = params['NextToken'] | |
else: | |
token = None | |
putparams(params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment