从用户数据文件调用AWS CLI [英] Calling AWS cli from user-data file
问题描述
从AMI映像启动EC2实例时,我有一个用户数据脚本文件. 该脚本使用AWS,但出现"aws:找不到命令". AWS-CLI作为AMI的一部分安装(实例启动后就可以使用它),但是由于某种原因,脚本无法找到它.
I have a user-data script file when launching an EC2 instance from an AMI image. The script uses AWS but I get "aws: command not found". The AWS-CLI is installed as part of the AMI (I can use it once the instance is up) but for some reason the script cannot find it.
我错过了什么吗?在加载图像之前运行用户数据脚本的任何机会(我很难相信)? 也许此时尚未设置路径env变量?
Am I missing something? any chance that the user-data script runs before the image is loaded (I find it hard to believe)? Maybe the path env variable is not set at this point?
谢谢
推荐答案
在加载图像之前运行用户数据脚本的任何可能性
any chance that the user-data script runs before the image is loaded
当然不是.这是运行脚本的映像上的服务.
No certainly not. It is a service on that image that runs the script.
也许此时尚未设置path env变量
Maybe the path env variable is not set at this point
这很可能是问题所在.脚本以root
而不是ec2-user
的身份运行,并且无法访问您可能在ec2-user
帐户中配置的路径.如果您尝试指定/usr/bin/aws
而不是仅指定aws
会发生什么?
This is most likely the issue. The scripts run as root
not ec2-user
, and don't have access to the path you may have configured in your ec2-user
account. What happens if you try specifying /usr/bin/aws
instead of just aws
?
这篇关于从用户数据文件调用AWS CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!