[英]aws ec2 run-instances: script as the plain text is ignored
我试图将脚本作为 --user-data 参数传递。 如果同样通过--user-data file://some_file.sh
运行, --user-data file://some_file.sh
一切正常。 此外,如果通过在相应的启动配置框中添加用户数据通过 AWS GUI 启动实例,它也可以工作。
我的 CLI 命令是
aws ec2 run-instances --image-id ami-0cc0a36f626a4fdf5 --count 1 --instance-type t2.micro --key-name key_name --security-group-ids sg-00000000 --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=some_name}]" --output table --user-data "sudo touch /tmp/install.log && sudo chmod 777 /tmp/install.log && echo $(date) >> /tmp/install.log"
如果与脚本一样运行,则其内容格式如下
#!/bin/bash
sudo touch /tmp/install.log
sudo chmod 777 /tmp/install.log
echo $(date) >> /tmp/install.log
另外,我想提一下,我尝试以不同的格式传递字符串,例如:
--user-data echo "some text"
--user-data "command_1\\n command_2\\n"
--user-data "command_1 && command_2"
--user-data "command_1; command_2;"
--user-data "#!/bin/bash; command_1; command_2;"
启动后的用户数据可见但未执行
$ curl -L http://169.254.169.254/latest/user-data/
第一行必须以#!
.
然后,执行后续行。 它们必须由适当的换行符分隔。 看起来\\n
没有正确解释。
$ aws ec2 run-instances --image-id ami-16d4986e --user-data '#!/bin/bash
> poweroff'
作为一个实验,我把它放在run-instances
命令的末尾:
aws ec2 run-instances ... --user-data '#!
echo bar >/tmp/foo
'
当我登录实例时,我可以看到/tmp/foo
文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.