【发布时间】:2020-05-28 18:16:54
【问题描述】:
我正在尝试在创建时使用 AWS CLI run-instances 命令将用户数据传递给我的 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 CLI 命令(带和不带 .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 仍然不接受用户数据。
我创建了一个安全组,其端口为 80 和 22,源为 0.0.0.0/0 使用默认 VPC 和子网。
AMI:Amazon Linux 2 - t2.micro
Region: us-east-1
问题:
- HTTPD 未安装。
- index.html 未在路径中创建。
我做错了吗?为什么它不起作用?
还有其他方法可以解决这个问题吗?
关于这个问题的新更新:
我传递给run-instances 命令的用户数据正在安装,但它花费了太多时间。
并非一直都在安装。我运行了五次代码,只有 3 个 EC2 安装了用户数据。
来自 AWS 状态网页:我发现 us-east-1 有很多延迟问题。
【问题讨论】:
-
实例是否在公有子网中,以便可以从 Internet 下载文件?您是否查看过
/var/log/cloud-init-output.log以确认脚本正在执行并检查错误? -
我同意@JohnRotenstein,检查日志文件。我无法重现您遇到的问题。您确定安装它的默认子网在您的 VPC 之外有一条路由吗?你能手动运行这些命令吗?
-
@JohnRotenstein 是的,实例放置在公共子网中。
-
@kenlukas,我能够通过 SSH 连接到该实例并手动运行每个命令。
标签: amazon-web-services amazon-ec2 command-line-interface aws-cli