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)

asked 2 years ago266 views
1 Answer
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
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions