HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to move EC2 instance to another ECS cluster

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
ecsec2moveinstanceanotherhowcluster

Problem

Assume I have two clusters devcluster and qacluster on ECS.
How to remove an EC2 instance (ecs-optimized amazon-linux) from qacluster and add to devcluster?

Solution

You need to follow these steps:

  • Set ECS_CLUSTER=devcluster in /etc/ecs/ecs.config



  • Stop all tasks/containers



  • Remove checkpoint file - /var/lib/ecs/data/ecs_agent_data.json



  • Start ECS agent again as explained here - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-install.html



To make sure it uses correct cluster, check logs - docker logs ecs-agent. It should have a message like:

[INFO] Registration completed successfully. I am running as 'arn:aws:ecs:eu-west-1:ACCOUNT_ID:container-instance/CLUSTER_ID' in cluster 'devcluster'

Code Snippets

[INFO] Registration completed successfully. I am running as 'arn:aws:ecs:eu-west-1:ACCOUNT_ID:container-instance/CLUSTER_ID' in cluster 'devcluster'

Context

StackExchange DevOps Q#2048, answer score: 6

Revisions (0)

No revisions yet.