Cleaning Up Your Amazon ECS Resources
Of course, if you're not using your ECS resources, it's time to clean them up. Scale them down, delete the services, then deregister them from AWS.
Join the DZone community and get the full member experience.
Join For FreeIn my previous blog posts on AWS (Introduction to Amazon ECS | Launch Amazon ECS cluster | Scaling With Amazon ECS | Deploying Updated Task Definitions/Docker images), I gave an overview on Amazon ECS with a walkthrough on how to launch Amazon ECS and then deploy a sample app by creating a task definition, scheduling tasks, configuring a cluster, and scaling in and out. We also covered creating new revisions for the existing task definitions to deploying the latest updated Docker images.
In this article, we will have a look at cleaning up the Amazon ECS resources that we have created so far. Once you have launched the Amazon ECS cluster and try to terminate container instances in order to clean your resources up, you won’t be able to do so because of Cloud Formation.
Below are the steps that you have to follow in order to clean up Amazon ECS resources.
Scale Down Services
Firstly, we have to scale down the desired count of tasks to ‘0’ for all the services running in a cluster so that Amazon ECS does not try to start new tasks in our container instances while we are cleaning up.
Delete Services
Then we must delete the same services inside that cluster. After our service has scaled down to ‘0’ tasks, we can delete it. But if you try to delete the service before scaling it down to ‘0,’ then Amazon ECS won’t let you do so.
Deregister Task Definitions
Under the Task definition navigation pane, select all the revisions of a definition that you want to clean up and click on Deregister.
Deregister Container Instances
Before we can delete a cluster, we must deregister the container instances inside that cluster. For each container instance inside our cluster, it's a matter of selecting them and deregistering them as shown below.
Delete a Cluster
Finally, we have removed the active resources from our Amazon ECS cluster. Go to the Clusters navigation pane and delete the cluster by clicking on the ‘Delete cluster’ button.
This will clean up your cluster recourses.
I hope through this series of blogs, you are now able to launch Amazon ECS cluster, deploy your application in a container environment, and easily scale in/scale out your tasks and container instances.
If you have any question/concerns, please feel free to ask. I’ll be more than happy to help you.
Published at DZone with permission of Prashant Goel, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments