amazon-web-services - 使用 pip 在实例上安装 aws cli
问题描述
我在启动期间使用云形成模板在我的实例上安装 CLI,但是当我尝试运行任何具有 cli 命令的 shell 脚本时,它会显示“aws configure”错误。由于权限问题,我无法将任何角色或 IAM 用户附加到实例。
如果还有其他实现相同的方法,请提供帮助。
外壳脚本
#!/bin/bash
my_eth1=`aws ec2 describe-network-interfaces --filters "Name=status,Values=available" "Name=tag:Name,Values=MyENI" "Name=subnet-id,Values=subnet-03754b9bf4816284e" --output text --query "NetworkInterfaces[0].PrivateIpAddress"`
my_eth1_id=`aws ec2 describe-network-interfaces --filters "Name=status,Values=available" "Name=tag:Name,Values=MyENI" "Name=subnet-id,Values=subnet-03754b9bf4816284e" --output text --query "NetworkInterfaces[0].NetworkInterfaceId" | grep -o 'eni-[a-z0-9]*'`
ec2_id=`curl http://169.254.169.254/latest/meta-data/instance-id`
aws ec2 attach-network-interface --network-interface-id $my_eth1_id --instance-id $ec2_id --device-index 1
GATEWAY=`ip route | awk '/default/ { print $3 }'`
printf "\nGATEWAYDEV=eth0\n" >>/etc/sysconfig/network
printf "\nBOOTPROTO=dhcp\nDEVICE=eth1\nONBOOT=yes\nTYPE=Ethernet\nUSERCTL=no\n" >/etc/sysconfig/network-scripts/ifcfg-eth1
ifup eth1
ip route add default via $GATEWAY dev eth1 tab 2
ip rule add from $my_eth1/32 tab 2 priority 600
云的形成
"UserData": { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -xe\n",
"echo 'Downloading PIP'\n",
"curl -O https://bootstrap.pypa.io/get-pip.py\n",
"echo 'Executing PIP using Python'\n",
"python get-pip.py --user\n",
"echo 'Setting PIP Classpath'\n",
"echo 'export PATH=~/.local/bin:$PATH' >> ~/.bash_profile\n",
"echo 'Reloading bash_profile'\n",
"source ~/.bash_profile\n",
"echo 'Installing AWS CLI'\n",
"pip install awscli --upgrade --user\n"
]]}}
解决方案
推荐阅读
- elisp - 需要扩展elisp函数
- excel - Excel 公式和条件格式:如何根据条件匹配另一个表中的当前单元格
- vulkan - 主机写保证源访问范围
- c# - 设置时间格式时出错,无法设置范围类的 numberformat 属性
- ios - IOS GAP Central 未发现外围设备
- javascript - 是否可以使用变量从函数内部动态调用 Azure 函数的 Cosmos DB 输入绑定的 SQL 查询?
- python - 具有自定义排序功能的 Altair 堆叠区域
- azure - 无法从启用了软删除的 Key Vault 中删除机密
- html - 如何更正 li 框的高度并将其中的文本居中?CSS
- mysql - 如何将一个表中的单词替换为另一个表中的行号