Simple python script for multiple parameter control in Amazon Parameter
Store Install Just install
Python3 and boto3 module.
sudo apt install -y python3 python3-pip python3-venvBetter practice is to use venv.
python3 -m venv venvsource venv/bin/activatepip3 install -r requirements.txtTo exit the venv just use deactivate command.
- Easy to copy existing parameters for new environment
Script get parameters by path, change names and can upload or save it local - Get parameters by path
Just read Parameter Store and get you parameters in JSON format to your terminal - Script don't get parameters which are ManagedBy Terraform
Because this tag is excluded - Save to file in
jsonor.envformat
Don't use env use.env - Read from
jsonor.envfile
You can specify this formats. JSON file need to have "Name" and "Value" fields! "Type" is optional, the default value is "String" - Rename part of parameters names
Just change, for example /project/dev/app to /project/qa/app in parameters names - Upload parameters from file or in action after renaming. Also you can overwrite existing parameters
Just put all parameters to Parameter Store with specifyed credentials. Script use your default.aws/credentialsfile, which you can create by commandaws configure. It's simple setup such for aws cli! - Delete parameters by path
Script creates backup of current parameters by specified path. It requires input confirmation of deleting. If you use script with-qargument, it will don't have any backups! Be careful! - Assume role for session
You can assume role in children account using specified account ID and role name for it. Read the documentation provided below! - Specify a region for Parameter Store
_By default script uses region from.aws/configfile _ - Script makes backups automaticaly when you delete or upload parameters
Just saves current parameters toparameters_dump_<current-time>.jsonfile. You can restore it later!
Main usage case:
python3 ssm.py --profile project --read .env -a /project/dev/app/ -U -oFor secure parameters:
python3 ssm_secure.py --profile project --read .env -a /project/dev/app/ -U -oReplace dev to qa in all parameter names from /sokol/dev/ path in SSM and upload new names. It will help you if if you need to copy parameters for new environment:
python3 ssm.py --profile default --path /sokol/dev/ --from dev --to qa --uploadShort version:
python3 ssm.py -P default -p /sokol/dev/ -f dev -t qa -UDo it in region:
python3 ssm.py -P default -p /sokol/dev/ -f dev -t qa -U --region us-west-2Now do the same in prod account:
python3 ssm.py -P profile_name -p /project/dev/ -f dev -t qa --region us-west-1 --id 1111111111111 --role ProductionRoleForExampleit will create a backup file with parameters by origin path
Get all parameters by path:
python3 ssm.py --profile default --path /python3 ssm.py -P default -p /sokol/dev/ -s .envor
python3 ssm.py -P default -p /sokol/dev/ -s my_parameters.jsonDelete parameters by path:
python3 ssm.py -P default -p /sokol/dev/ -DDelete parameters from file:
python3 ssm.py -P default -r .env -DUpload parameters from file:
python3 ssm.py -P default -r .env -URead the documentation about switching roles and about organization in AWS.
Also you can read how it works for this script and what requirements it have.
Just use:
python3 ssm.py -P johnrace -p /project/prod/ --id 1111111111111 --role ProductionRoleForExampleNow you
R - Required
O - Optional
BR(number of group) - Both required
Use both --replace and --to arguments!
| Parameter | Required | Description |
|---|---|---|
-P,--profile |
R | Specify the AWS profile for script’s session |
-p,--path |
R | SSM parameters path ex: /my/first/param/ |
--region |
O | Specify an AWS region |
--id |
O/BR1 | Specify an account ID for assuming role |
--role |
O/BR1 | Specify a role name in children account |
-r,--read |
O | Flag to read the parameters from JSON or env file in current folder. Use filename.extension format |
-s,--save |
O | Flag to save the parameters into JSON or env file |
-U,--upload |
O | Flag to upload new parameters. It will make a backup if you don’t use -q flag |
-D,--delete |
O | Flag to delete the parameters. Need input confirmation! |
-q,--quiet |
O | Flag to don't create backups |
-c,--clear |
O | Flag to delete all parameters_dump_*.json files in current directory |
-a,--add-path |
O | Add path to parameter. If you load from .env file this argument is required! |
-f,--from |
O/BR2 | Specify a part of string to rename |
-t,--to |
O/BR2 | Specify a new part of string |
-o,--overwrite |
O | Flag to overwrite parameters |
