在创建时,我正试图使用命令将用户数据传递给我的EC2实例。
我将下面的命令放在一个文件中:
#!/bin/bash
sudo su
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
echo "<html><h1>Welcome to the server</h1><html>" >> /var/www/html/index.html我运行的所有AWS命令(使用.txt和不使用):
aws ec2 run-instances --image-id ami-062f7200baf2fa504 --count 1 --instance-type t2.micro --key-name lab115key --security-groups my-sg --region us-east-1 --user-data file://./text1.txtaws ec2 run-instances --image-id ami-062f7200baf2fa504 --count 1 --instance-type t2.micro --key-name lab115key --security-groups my-sg --region us-east-1 --user-data file://./text1aws ec2 run-instances --image-id ami-062f7200baf2fa504 --count 1 --instance-type t2.micro --key-name lab115key --security-groups my-sg --region us-east-1 --user-data text1.txtaws ec2 run-instances --image-id ami-062f7200baf2fa504 --count 1 --instance-type t2.micro --key-name lab115key --security-groups my-sg --region us-east-1 --user-data text1然后,我尝试将脚本编码为Base64,但用户数据仍未被接受。
我使用默认的VPC和Subnet创建了一个端口80和22的Security,源代码为0.0.0.0/0。
AMI: AmazonLinux2-t2.微
Region: us-east-1发行:
installed.
我做错了什么吗?为什么不起作用?
还有别的办法解决这个问题吗?
关于这一问题的最新情况:
我传递给run-instances命令的用户数据正在安装中,但需要花费太多的时间。
并不是所有的时间,它被安装。我运行了五次代码,只有3个EC2安装了用户数据。
从AWS状态网页:我发现us-east-1存在很多延迟问题。
发布于 2020-02-14 04:41:24
通过用户数据提供的命令作为foot用户执行。
因此,在用户数据脚本中,sudo不使用命令。
在Amazon上执行用户数据脚本时出现的任何错误都可以在以下文件中找到:
/var/log/cloud-init-output.log如果您不确定脚本是否正在执行,请在标题行后面添加如下行:
echo Script started > /tmp/script.log然后,您可以检查/tmp/script.log的内容,以确定是否执行了脚本。
https://stackoverflow.com/questions/60201060
复制相似问题