简体   繁体   English

如何从 aws 参数存储中导出参数并导入另一个帐户

[英]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>"会有点困难,因为我的参数太多了。

  1. Retrieve all parameters via aws ssm get-parameters-by-path --path "/relative/path/" --recursive通过aws ssm get-parameters-by-path --path "/relative/path/" --recursive检索所有参数
  2. Write the resulting JSON somewhere down - eg into a file将生成的 JSON 写入某处 - 例如写入文件
  3. Prepare put commands eg with JS准备 put 命令,例如用 JS
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(制表符分隔值)格式输出所有参数的NameTypeValue

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.

相关问题 AWS/Cloudformation:如何将参数值导出/导入到另一个堆栈 (YAML) - AWS/Cloudformation: How to export/import parameter value to another stack (YAML) 将 AWS 资源从一个账户导出到另一个账户 - Export AWS resources from one account to another 从 AWS Parameter Store 设置 Jenkins 参数 - Set Jenkins parameters from AWS Parameter Store 是否可以在同一区域的另一个 AWS 账户中共享 Parameter Store 密钥? - Is it possible to share Parameter Store keys in another AWS Account for same region? 如何将文件从一个AWS账户复制到另一个AWS账户 - How to copy files from one AWS account to Another AWS Account 如何将参数存储数据迁移到其他区域/AWS 账户 - How to migrate parameter store data to other Region / AWS Account 如何将变量的 terraform 输出导出/发布到 AWS SSM 参数存储 - how to export / post terraform output of variables to AWS SSM parameter store Spring Boot 从 AWS 参数存储读取参数 - Spring boot reading parameters from AWS parameter store 如何正确/安全地从 AWS SSM 参数存储中访问 EC2 实例上我的 Python 脚本的参数? - How to correctly/safely access parameters from AWS SSM Parameter store for my Python script on EC2 instance? 创建从 Parameter Store 中提取参数的 SSM 复合文档 - AWS - Creating a SSM Composite Document that pulls Parameters from Parameter Store - AWS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM