AWS 配置 Bash One Liner
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34839449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AWS Configure Bash One Liner
提问by blacklabelops
Can anybody tell me how to automate the aws configure in bash with a one liner?
有人能告诉我如何使用单衬在 bash 中自动配置 aws 吗?
Example:
例子:
$ 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
Application: I want to automate this inside a Docker Entrypoint!
应用程序:我想在 Docker 入口点内自动执行此操作!
回答by jarmod
If you run aws configure set help
you will see that you can supply settings individually on the command line and they will be written to the relevant credentials or config file. For example:
如果您运行,aws configure set help
您将看到您可以在命令行上单独提供设置,它们将被写入相关的凭据或配置文件。例如:
aws configure set aws_access_key_id AKIAI44QH8DHBEXAMPLE
aws configure set aws_access_key_id AKIAI44QH8DHBEXAMPLE
You can also run this interactively to modify the default credentials:
您还可以以交互方式运行它以修改默认凭据:
aws configure
aws configure
Or run it interactively to create/modify a named profile:
或者以交互方式运行它以创建/修改命名配置文件:
aws configure --profile qa
aws configure --profile qa
回答by killthrush
For those inclined to use bash, the following works quite well and keeps secrets out of your scripts. In addition, it will also save your input to a named profile in one go.
对于那些倾向于使用 bash 的人来说,以下内容非常有效,并且可以为您的脚本保密。此外,它还可以一次性将您的输入保存到命名配置文件中。
printf "%s\n%s\nus-east-1\njson" "$KEY_ID" "$SECRET_KEY" | aws configure --profile my-profile
回答by Thomas L.
If you want to automate you should use files rather than CLI. Your CLI only write those files.
如果你想自动化,你应该使用文件而不是 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 =
回答by cryanbhu
Building upon the suggestion by Tom in jarmod's answer, to "configure your keys in a config file that you then share with your docker container instead".
根据汤姆在 jarmod 的回答中的建议,“在配置文件中配置您的密钥,然后与您的 docker 容器共享”。
I found that slightly confusing as I'm new to using Docker and awscli.
Also, I believe most who end up at this question are similarly trying to use Docker and awscli
together.
我发现这有点令人困惑,因为我是使用 Docker 和 awscli 的新手。
此外,我相信大多数最终回答这个问题的人都同样尝试使用 Docker 并awscli
一起使用。
So what you'd want to do, step by step is:
所以你想要做的,一步一步是:
Create a credentials
file containing[default]
aws_access_key_id = default_access_key
aws_secret_access_key = default_secret_key
that you copy to ~/.aws/credentials
, using a line in Dockerfile likeCOPY credentials /root/.aws/credentials
创建一个credentials
包含[default]
aws_access_key_id = default_access_key
aws_secret_access_key = default_secret_key
您复制到的文件~/.aws/credentials
,使用 Dockerfile 中的一行,如COPY credentials /root/.aws/credentials
and a config
file containing[default]
region = us-west-2
output = table
that you copy to ~/.aws/config
, using a line in Dockerfile likeCOPY config /root/.aws/config
和一个config
包含[default]
region = us-west-2
output = table
您复制到的文件~/.aws/config
,使用 Dockerfile 中的一行,如COPY config /root/.aws/config
Reference:aws configure set help
参考:aws configure set help