Back to all patterns

Table of Contents

About

Development Tool

aws-cli

Type

script

Uninstall ECS Anywhere

A bash script that cleans up a host that was used as capacity for ECS Anywhere

Nathan Peck
Nathan Peck
Senior Developer Advocate at AWS

The following script removes the components of ECS Anywhere from a host. After running this you can reinstall ECS Anywhere back onto the host cleanly, and the host will have a new identity in SSM and in the ECS console.

File: uninstall-ecs-anywhere.sh Language: bash
1
2
3
4
5
apt remove -y amazon-ssm-agent amazon-ecs-init
rm -rf /var/lib/amazon/ssm/Vault/Store/RegistrationKey
rm -rf /var/lib/ecs/ecs.config
rm -rf /etc/ecs/ecs.config
rm -rf /var/lib/ecs/data/*

🚨 Danger: Be careful using this script. Each time you cleanup the SSM registration key and reregister the host it will be a new SSM managed instance with a new identity. This means it will add to your SSM cost.

Additionally you will still need to use the SSM console or API to clean up old managed instances in SSM that you no longer wish to track.

If you would like to have the instance maintain the same SSM identity you can modify the uninstall script to preserve the file /var/lib/amazon/ssm/Vault/Store/RegistrationKey. This way when you reinstall the SSM agent it will see the preexisting key and keep the same SSM identity.