EC2 instance is not registered in ECS cluster

0

I created an ECS cluster for EC2 Linux + Networking, spot instance from web UI wizard. However, the instances never appear on the UI. I double-checked roles and policies, and I believe every permission is granted.

In the instances, I found an error in the cloud-init log file /var/log/cloud-init-output.log saying:

/var/lib/cloud/instance/scripts/part-001: line 7: /etc/init/spot-instance-termination-notice-handler.conf: No such file or directory

The auto-generated user data is:

#!/bin/bash
echo ECS_CLUSTER=my-cluster >> /etc/ecs/ecs.config;echo ECS_BACKEND_HOST= >> /etc/ecs/ecs.config;
export PATH=/usr/local/bin:$PATH
yum -y install jq
yum install -y awscli
aws configure set default.region ap-northeast-1
cat <<EOF > /etc/init/spot-instance-termination-notice-handler.conf
... 

I didn't modify the script and apparently, there is no such directory /etc/init in the latest AMI (amzn2-ami-ecs-gpu-hvm-2.0.20220831-x86_64-ebs)

已提問 2 年前檢視次數 296 次
1 個回答
0

the error is happening because the /etc/init directory does not exist in ec2. add a mkdir /etc/init before the cat <<EOF > in your userdata.

#!/bin/bash
echo ECS_CLUSTER=my-cluster >> /etc/ecs/ecs.config;echo ECS_BACKEND_HOST= >> /etc/ecs/ecs.config;
export PATH=/usr/local/bin:$PATH
yum -y install jq
yum install -y awscli
aws configure set default.region ap-northeast-1
**mkdir /etc/init**
cat <<EOF > /etc/init/spot-instance-termination-notice-handler.conf
已回答 10 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南