使用pip在实例上安装AWS CLI

时间:2018-08-30 10:01:11

标签: amazon-web-services amazon-cloudformation

我正在使用云形成模板在启动期间在实例上安装CLI,但是当我尝试运行任何具有cli命令的shell脚本时,它显示“ aws configure”错误。由于权限问题,我无法将任何角色或IAM用户附加到实例。

如果还有其他方法可以达到同样的效果,请帮助。

Shell脚本

#!/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"
            ]]}}

0 个答案:

没有答案