还有一组脚本和shell函数,用于管理aws配置文件和跨帐户访问。
aws-shelltools的Python项目详细描述
还有一组用于管理aws概要文件的脚本和shell函数 以及跨账户访问。
安装
安装到python虚拟环境中:
source ~/path-to-venv/bin/activate pip install aws-shelltools
从可编辑的本地存储库安装:
git clone https://github.com/ucopacme/aws-shelltools cd aws-shelltools pip install -r requirements.txt pip install -e .
卸载:
pip uninstall aws-shelltools
配置:
aws-shelltools-setup . ~/.bashrc
外壳工具:
- AWS剖面图
- 设置或显示shell环境变量aws_profile的值
- AWS区域
- 设置或显示shell环境变量aws_default_profile的值
- 美国焊接学会环境
- 打印所有AWS环境变量的当前值
- aws设置mfa令牌
- 从aws sts请求临时会话凭据。导出这些凭据 到当前shell中的环境变量。
- AWS生成配置
- 通过列出组假定角色策略生成aws客户端配置文件。你 必须在运行此命令之前设置MFA令牌。
- aws列出角色
- 打印可用aws的角色配置文件列表。
- aws承担角色
- 运行“aws sts assempt role”操作以获取临时的假定角色 指定配置文件的凭据。将这些凭据导出到 当前外壳中的环境变量。
- aws刷新
- 重置mfa令牌。如果环境变量aws_assumed_role_profile已经 从上一个会话设置,然后重新运行“aws sts assume role”操作 对于该配置文件。
- aws显示假定的角色
- 打印aws假定角色环境变量的当前值
- aws whoami
- aws sts get caller identity的打印输出
- 美国焊接学会出口环境
- 将aws环境变量缓存到本地文件以供其他shell使用
- AWS导入环境
- 将缓存的aws环境变量计算到当前shell中
- aws放弃假定的角色
- 在担任角色之前将aws会话环境变量重置为值
- aws未设置mfa令牌
- 取消设置所有aws会话令牌环境变量
用法:
# Run each command with -h option for full usage info. aws-profile [<profile>] aws-region [<region>] aws-set-mfa-token aws-make-config aws-list-roles aws-assume-role <profile> aws-refresh aws-display-assumed-role aws-whoami aws-env aws-export-env aws-import-env aws-drop-assumed-role aws-unset-mfa-token
配置假定角色配置文件
如果尚未设置aws cli访问权限,请跳到Awscli/Python Setup部分 在继续之前。
设置您的MFA令牌并将角色设置为您配置的一个“假定角色”配置文件:
(python3.6) ashleygould$ aws-set-mfa-token please enter 6 digit token code for your MFA device: 351918 (python3.6) ashleygould$ aws-assume-role ashley-training-OrgAdmin (python3.6) ashleygould$ aws-whoami { "UserId": "AROAIMADVT2W7CODNCP7W:agould@ashley-training-OrgAdmin", "Account": "111111111111", "Arn": "arn:aws:sts::111111111111:assumed-role/OrgAdmin/agould@ashley-training-OrgAdmin" }
现在您可以运行aws make config来生成基于 在中央auth帐户中的组成员身份。这些是写给 ~/.aws/config.d/config.aws外壳工具:
(python3.6) ashleygould$ aws-make-config (python3.6) ashleygould$ head ~/.aws/config.d/config.aws_shelltools [profile ashley-training-OrgAdmin] role_arn = arn:aws:iam::111111111111:role/awsauth/OrgAdmin role_session_name = agould@ashley-training-OrgAdmin source_profile = default [profile Auth-OrgAdmin] role_arn = arn:aws:iam::222222222222:role/awsauth/OrgAdmin role_session_name = agould@Auth-OrgAdmin source_profile = default
查看列表或所有可用的AWS配置文件:
(python3.6) ashleygould$ aws-list-roles profile Auth-OrgAdmin profile OrgMaster-OrgAdmin profile ashley-training-OrgAdmin profile eas-dev-OrgAdmin profile eas-prod-OrgAdmin
您可以在命令行将配置文件名缩短为唯一的前缀:
(python3.6) ashleygould$ aws-assume-role eas Your specified profile 'eas' matches multiple configured profiles. Select one from the list below and try again: eas-dev-OrgAdmin eas-prod-OrgAdmin ucop-itssandbox-eas-OrgAdmin (python3.6) ashleygould$ aws-assume-role eas-dev (python3.6) ashleygould$ aws-whoami { "UserId": "AROAJFPJVRDRDFUZJLZVG:agould@eas-dev-OrgAdmin", "Account": "111111111111", "Arn": "arn:aws:sts::111111111111:assumed-role/OrgAdmin/agould@eas-dev-OrgAdmin" }
awscli/python设置
上面的安装说明假设您对python有一定的了解 还有awscli。如果您是新手,请参阅优秀的AWS文档: https://docs.aws.amazon.com/cli/latest/userguide/installing.html
这包括python和python虚拟环境在linux上的安装, MacOS和Windows。一旦python满意了,运行 aws shelltools将确保awscli`和'boto3也正确安装。
AWS访问密钥设置
在使用这些东西之前,必须创建aws访问密钥并 秘密访问密钥并确认您的aws外壳配置文件。见: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
登录aws控制台,根据aws文档创建aws访问密钥。从你的 shell运行aws configure命令并剪切并粘贴访问密钥/密钥 按提示从控制台输入到命令行。这将创建 默认值配置文件:
(python3.6) ashleygould$ aws configure AWS Access Key ID [None]: AKI**********W5AFPSNQ AWS Secret Access Key [None]: U/QotA**********************543vuYB Default region name [None]: us-west-2 Default output format [None]: (python3.6) ashleygould$ cat .aws/config [default] region = us-west-2 (python3.6) its-agould-9m:~ ashleygould$ aws-whoami { "UserId": "AIDAJ2SLREGRDKVFOB6CI", "Account": "112233445566", "Arn": "arn:aws:iam::112233445566:user/awsauth/orgadmin/agould" }
使用codecommit存储库
要在承担角色后从命令行访问codecommit存储库, 必须首先将git配置为使用aws codecommit凭据帮助程序:
git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath true