AWS ECS

How to manually delete a cluster in case the pipelines do not work?

  1. Find the target cluster to delete -> Go to Tasks tab -> Hit Stop All button
  2. Go back to Services tab -> Click on the service -> Hit Delete button
  3. Go to ALB page under EC2 service -> Find target ALB you want to delete -> Go to its Listeners tab -> Go into the listeners list and find target groups associated with that listener (default and current ones if applicable) -> Find those target groups in the Target Groups view
  4. Go back to ALB Listeners tab -> Delete that listener
  5. Go to the Target Groups view -> Delete those target group(s). Make sure you search for all the target groups for that stack. Look for prefix (search by the name of your application) to identify the target groups belonged to that stack
  6. Go to the Auto Scaling Groups view -> Delete the auto scaling group(s)
  7. Go to the Launch Configuration view -> Delete the launch configuration(s)
  8. Go to the Load Balancer view -> Delete the target load balancer (you will need to edit the ALB attribute, and disable the Delete Protection option)
  9. Go to the Target Groups view -> Look for any target group associated with that stack.
  10. Go to the ECS view -> Delete the target cluster
  11. Done

How to get environment variables in ECS container?

Environment variables are defined inside the container and some are passed in the task definition. So you can use describe-task-definition to see the extra variables.

If you are using the console, just go the task definition and look at “Environment variables”.

How to deploy a previous version of a service in ECS if an incorrect version of code is deployed by mistake?

ECS -> Clusters -> service-group -> services -> name-of-the-application -> Update

In the dropdown for “Revision”, pick an older version.

Select “Force new deployment” radio button and run it.

That will deploy the older version.

Monitor the tasks to see that tasks with newer version go away and tasks with older version get created.

Task definition

How can you find out which version of your application is deployed in a given environment?

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definitions.html

A task definition is a blueprint for your application. It is a text file in JSON format that describes the parameters and one or more containers that form your application.


Links to this note