Amazon web services 使用pip在实例上安装aws cli

Amazon web services 使用pip在实例上安装aws cli,amazon-web-services,amazon-cloudformation,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,Val

在启动期间,我正在使用云形成模板在我的实例上安装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"
            ]]}}

添加访问密钥、密钥令牌和区域。您使用的是什么AMI,默认情况下Amazon Linux AMI已经安装了它。我总是希望使用安装cli。我使用的是red hat ami,默认情况下没有cli。有没有办法从shell脚本中配置aws cli(aws configure…)?如果您可以在发布错误消息时删除任何敏感信息(如果有的话),这将非常有用