[英]How to export parameters from aws parameter store and import into another account
on my first aws account I have parameters specified in the following manner:在我的第一个aws 帐户中,我以以下方式指定了参数:
/config/a => value1
/config/b => value2
/config/c/a => value31
/config/c/b => value32
I want to move these to my second aws account.我想将这些移至我的第二个aws 帐户。
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.使用
aws ssm get-parameters --names "<param-name>"
会有点困难,因为我的参数太多了。
aws ssm get-parameters-by-path --path "/relative/path/" --recursive
aws ssm get-parameters-by-path --path "/relative/path/" --recursive
检索所有参数for (const value of params.Parameters) {
const { Name, Value } = value;
console.log(`aws ssm put-parameter --name "${Name}" --value "${Value}" --type "String"`);
}
I created a utility which does exactly what you want:我创建了一个实用程序,它完全符合您的要求:
pip install aws-ssm-copy
aws-ssm-copy --dry-run --source-profile <source> --recursive /
Checkout the aws-ssm-copy utility and blog for more details.查看aws-ssm-copy实用程序和博客了解更多详细信息。
May be get-parameters-by-path suits here: aws ssm get-parameters-by-path --path "/" --recursive
可能是 get-parameters-by-path 适合这里:
aws ssm get-parameters-by-path --path "/" --recursive
https://docs.aws.amazon.com/cli/latest/reference/ssm/get-parameters-by-path.html#synopsis https://docs.aws.amazon.com/cli/latest/reference/ssm/get-parameters-by-path.html#synopsis
Here is my version that outputs all parameters' Name
, Type
and Value
in a TSV (tab-separated values) format:这是我的版本,它以 TSV(制表符分隔值)格式输出所有参数的
Name
、 Type
和Value
:
aws ssm get-parameters-by-path --path "/" --recursive --query="Parameters[*].[Name, Type, Value]" --output text
Example response:示例响应:
/prod/aaa String xxx
/prod/bbb String yyy
/prod/ccc String zzz
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 --with-decryption --region eu-west-2
you will get a JSON
formatted response.您将收到
JSON
格式的响应。 Just copy the response and paste it into a file ( *.txt
file then rename it to *.json
).只需复制响应并将其粘贴到文件中(
*.txt
文件,然后将其重命名为*.json
)。 You have your JSON file with all the current parameters您拥有包含所有当前参数的 JSON 文件
I published that code into a git repository here .我在此处将该代码发布到 git 存储库中。 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')
;和你的
json
文件: 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
然后通过运行命令
npm install
安装npm
包并通过命令npm start
运行脚本
使用以下 cmd,您可以轻松获取参数存储的名称和值。
$ aws ssm get-parameters-by-path --path "/" --recursive --query="Parameters[*].[Name, Value]" --output json>parameters.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.