用于安装 AWS CLI 工具的 Bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24536583/
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
Bash script to install AWS CLI tools
提问by Rahul Mehrotra
I am writing a bash script that will automatically install and configure AWS CLI tools. I am able to install AWS CLI tools but unable to configure it.
我正在编写一个 bash 脚本,它将自动安装和配置 AWS CLI 工具。我能够安装 AWS CLI 工具,但无法对其进行配置。
My script is something like this:
我的脚本是这样的:
#!/bin/bash
wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
./awscli-bundle/install -b ~/bin/aws
./awscli-bundle/install -h
aws configure
AWS Access Key ID [None]: ABCDEFGHIJKLMNOP ## unable to provide this data
AWS Secret Access Key [None]: xbdwsdADDS/ssfsfa/afzfASADQASAd ## unable to provide this data
Default region name [None]: us-west-2 ## unable to provide this data
Default output format [None]: json ## unable to provide this data
I wish to do the configuration using this script too. I wish that I can provide these credentials via script so that it prevents manual entry. How can this be done?
我也希望使用此脚本进行配置。我希望我可以通过脚本提供这些凭据,以防止手动输入。如何才能做到这一点?
回答by Ben Whaley
Use a configuration file rather than the aws configure
command. Create a file called ~/.aws/config
that looks like this:
使用配置文件而不是aws configure
命令。创建一个名为的文件~/.aws/config
,如下所示:
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
region=us-west-2
output=json
More info in the docs.
文档中的更多信息。
回答by Daljit Sinz
the best practice is to install the awscliutility by BASH and copy the file from your own specified location of 2 files
最佳实践是通过 BASH安装awscli实用程序并从您自己指定的 2 个文件位置复制该文件
without hitting
不打
#aws configure
command these files will not get created, you can copy and paste the files using bash script and get all the execution done
命令不会创建这些文件,您可以使用 bash 脚本复制和粘贴文件并完成所有执行
~/.aws/credintials
~/.aws/config
where credentials contains
其中凭证包含
[default]
aws_access_key_id=ABCDEFGHIJKLMNOP
aws_secret_access_key=xbdwsdADDS/ssfsfa/afzfASADQASAd
and config file contains
和配置文件包含
[default]
output=json
region=us-west-2
This will help you to keep the keys at one place and you can also push the same for your execution for any CMT tool as well like Ansible.
这将帮助您将密钥保存在一个地方,您还可以为任何 CMT 工具以及 Ansible 的执行推送相同的密钥。
回答by michael emens
you additionally configure this from the command line which will create the configuration file
您还可以从命令行配置它,这将创建配置文件
aws configure set aws_access_key_id ABCDEFGHIJKLMNOP
aws configure set aws_secret_access_key xbdwsdADDS/ssfsfa/afzfASADQASAd
aws configure set default.region eu-west-1