土. 10月 8th, 2022

はじめに

ECSで割り当てたEC2が、クラスタに参加できない場合の対処。

What to do when EC2 assigned by ECS cannot join the cluster.

tail -f  /var/log/ecs/ecs-agent.log.2019-11-12-04 

2019-11-12T04:20:19Z [INFO] Restored from checkpoint file. I am running as 'arn:aws:ecs:ap-northeast-1:xxx:container-instance/xxx:container-4f04-xxx:container-9da7-xxx:container' in cluster 'account-web-ec2'
2019-11-12T04:20:19Z [INFO] Remaining mem: 3885
2019-11-12T04:20:19Z [ERROR] Unable to register as a container instance with ECS: ClientException: Referenced container instance xxx:container-4f04-xxx:container-9da7-xxx:container not registered.
	status code: 400, request id: xxx:container-xxx:container-47a3-90a6-xxx:container
2019-11-12T04:20:19Z [ERROR] Error re-registering: ClientException: Referenced container instance xxx:container-4f04-xxx:container-9da7-xxx:container not registered.
	status code: 400, request id: ea19fb3f-06e3-47a3-90a6-xxx:container


2019-11-12T04:20:35Z [INFO] Loading configuration
2019-11-12T04:20:35Z [INFO] Image excluded from cleanup: amazon/amazon-ecs-agent:latest
2019-11-12T04:20:35Z [INFO] Image excluded from cleanup: amazon/amazon-ecs-pause:0.1.0
2019-11-12T04:20:35Z [INFO] Amazon ECS agent Version: 1.32.1, Commit: 4285f58f
2019-11-12T04:20:35Z [INFO] Creating root ecs cgroup: /ecs
2019-11-12T04:20:35Z [INFO] Creating cgroup /ecs
2019-11-12T04:20:35Z [INFO] Loading state! module="statemanager"
2019-11-12T04:20:35Z [INFO] Event stream ContainerChange start listening...
2019-11-12T04:20:35Z [INFO] Restored cluster 'account-web-ec2'
2019-11-12T04:20:35Z [WARN] Unable to obtain Outpost ARN from EC2 Metadata: EC2MetadataError: failed to make EC2Metadata request

対処

待てども待てどもクラスタに参加できない場合は、

If you can’t join the cluster,

“` /var/lib/ecs/data/ecs_agent_data.json “`

を削除(もしくは退避)させることで、クラスタに参加できるようになる。
成功すると以下の通りになる。

By deleting (or evacuating), you can join the cluster.
If successful output is below

 tail -f  /var/log/ecs/ecs-agent.log.2019-11-12-04 
2019-11-12T04:25:31Z [INFO] Registration completed successfully. I am running as 'arn:aws:ecs:ap-northeast-1:xxxx:container-instance/xxxx-xxxx-xxxx-xxxx-xxxx' in cluster 'account-web-ec2'
2019-11-12T04:25:31Z [INFO] Saving state! module="statemanager"
2019-11-12T04:25:31Z [INFO] Beginning Polling for updates
2019-11-12T04:25:31Z [INFO] Event stream DeregisterContainerInstance start listening...
2019-11-12T04:25:31Z [INFO] Initializing stats engine

参考情報

https://dev.classmethod.jp/etc/ecsec2_cluster_failed/