AWS配置Bash One Liner

bla*_*ops 22 bash amazon-web-services docker

任何人都可以告诉我如何使用单线程自动化bash配置bash?

例:

$ aws configure --profile user2
AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE
AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: text
Run Code Online (Sandbox Code Playgroud)

应用程序:我想在Docker入口点内自动执行此操作!

jar*_*mod 28

如果运行,aws configure set help您将看到可以在命令行上单独提供设置,它们将被写入相关的凭据或配置文件.例如:

aws configure set aws_access_key_id AKIAI44QH8DHBEXAMPLE

您还可以以交互方式运行此操作以修改默认凭据:

aws configure

或者以交互方式运行它以创建/修改命名的配置文件:

aws configure --profile qa

  • 我强烈建议不要将访问密钥嵌入到脚本中,这是非常糟糕的做法.以Thomas L.为例,在配置文件中配置您的密钥,然后将其与docker容器共享 (6认同)
  • 我也提到了这一点,因为maybeg 愿意自动化其docker 容器部署,所以他很可能最终会得到嵌入他真正访问/秘密密钥的脚本。这是配置,不应混合在代码中(例如,不在 github 上提交等)。干杯 (2认同)

Erd*_* G. 27

一班轮

aws configure set aws_access_key_id "AKIAI44QH8DHBEXAMPLE" --profile user2 && aws configure set aws_secret_access_key "je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY" --profile user2 && aws configure set region "us-east-1" --profile user2 && aws configure set output "text" --profile user2
Run Code Online (Sandbox Code Playgroud)

注意:设置区域是可选的(如果没有任何区域,也不要将其设置为空字符串,否则会出现错误);以及用户配置文件,如果您不设置它,它将进入默认设置。

更好地练习Secret

使用秘密,然后使用关联的环境变量:

aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" --profile user2 && aws configure set aws_secret_access_key "$AWS_ACCESS_KEY_SECRET" --profile user2 && aws configure set region "$AWS_REGION" --profile user2 && aws configure set output "text" --profile user2
Run Code Online (Sandbox Code Playgroud)

了解更多


小智 11

我认为这就是一句话的答案

aws configure set aws_access_key_id $YOUR_ACCESS_KEY_ID; aws configure set aws_secret_access_key $YOUR_SECRET_ACCESS_KEY; aws configure set default.region $YOUR_AWS_DEFAULT_REGION
Run Code Online (Sandbox Code Playgroud)


Tho*_* L. 5

如果要自动化,则应使用文件而不是CLI。您的CLI仅写那些文件。

? cat ~/.aws/config
[profile_1]
output = json
region = eu-west-1
[profile_2]
output = json
region = eu-west-1

? cat ~/.aws/credentials
[profile_1]
aws_access_key_id =
aws_secret_access_key =
[profile_2]
aws_access_key_id =
aws_secret_access_key = 
Run Code Online (Sandbox Code Playgroud)


kil*_*ush 5

对于那些倾向于使用bash的人来说,以下内容可以很好地发挥作用并将秘密隐藏在脚本之外。此外,它还将一次性将您的输入保存到命名配置文件。

printf "%s\n%s\nus-east-1\njson" "$KEY_ID" "$SECRET_KEY" | aws configure --profile my-profile
Run Code Online (Sandbox Code Playgroud)


Mac*_*cio 5

一班轮

aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" --profile profile_name_here && aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY" --profile profile_name_here && aws configure set region "$AWS_REGION" --profile profile_name_here && aws configure set output "json" --profile profile_name_here
Run Code Online (Sandbox Code Playgroud)

设置个人配置

profile_name_here是要保存到您的 aws 配置中的 aws 配置文件名称。用你自己的替换它。

访问密钥

aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" --profile profile_name_here

秘密访问密钥

aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY" --profile profile_name_here

地区

aws configure set region "$AWS_REGION" --profile profile_name_here

输出

aws configure set output "json" --profile profile_name_here

此处指定的值是json ,但您可以从aws docs支持的输出格式列表中替换它。

  • json
  • yaml
  • yaml 流
  • 文本
  • 桌子

笔记:

如果您使用 CI,$AWS_ACCESS_KEY_ID$AWS_SECRET_ACCESS_KEY$AWS_REGIONAWS 凭证文件或环境变量中的变量。您还可以使用常规字符串值替换它们,但这并不安全。