How to export parameters from aws parameter store and import into another account

拟墨画扇 提交于 2020-05-29 03:59:46

问题


on my first aws account I have parameters specified in the following manner:

/config/a => value1
/config/b => value2
/config/c/a => value31
/config/c/b => value32

I want to move these to my second aws account.

I created these parameters in the parameter store manually.

How could I easily copy these values from one account to the other?

Using aws ssm get-parameters --names "<param-name>" would be a bit too difficult, since I have way too many parameters.


回答1:


May be get-parameters-by-path suits here: aws ssm get-parameters-by-path --path "/" --recursive

https://docs.aws.amazon.com/cli/latest/reference/ssm/get-parameters-by-path.html#synopsis




回答2:


  1. Retrieve all parameters via aws ssm get-parameters-by-path --path "/relative/path/" --recursive
  2. Write the resulting JSON somewhere down - e.g. into a file
  3. Prepare put commands e.g. with JS
for (const value of params.Parameters) {
    const { Name, Value } = value;
    console.log(`aws ssm put-parameter --name "${Name}" --value "${Value}" --type "String"`);
}



回答3:


well I know it is has been a year but, for people who are still trying to figure out here is the detailed solution,

So you need to run following command to fetch all the parameters in your current region:

aws ssm get-parameters-by-path --path "/" –recursive

you will get a JSON formatted response. Just copy the response and paste it into a file (*.txt file then rename it to *.json). You have your JSON file with all the current parameters

I published that code into a git repository here. Just clone that repository after cloning add your desired region here :

const ssm = new AWS.SSM({

apiVersion: '2014-11-06';,

region: 'eu-west-2'; // add your destination region here.

});

and your json file here: const { Parameters } = await require('<YOUR JSON FILE>.json');

Then Install npm packages by running command npm install and run the script by command npm start



来源:https://stackoverflow.com/questions/54787151/how-to-export-parameters-from-aws-parameter-store-and-import-into-another-accoun

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!