Getting EC2 instances ID's of terminated instances
Issue
In INT account we’ve got daily environment shutdown in order to save costs on off hours. The problem is that with that we’re loosing instance CPU graph info. The good thing that data is there on CloudWatch we just need to get instances id to be able to check it.
Solution:
All instances ids that got created for cluster and/or got terminated during cluster pause are logged inside ASG (auto scaling group) logs. The only thing that needed is to get unique instances ids and put them into CloudWatch dashboard.
*in this particular case we’ll use mcpt-pvt cluster as an example.
To see logs from AWS console: navigate to specific ECS cluster, click on infrastructure, click on ASG (autoscaling group) then go on tab activity. Here is ASG activity logs will be shown (like creating instances terminating instances etc.). This logs is already sorted and parsed by ASG service.
In order to see raw logs - navigate to AWS CloudWatch log insight service and choose appropriate log group:
Run query like:
fields @instanceId
|filter @logStream like "/ecs"
|parse @logStream "/*/ecs" as instanceId
|dedup @logStream
| limit 10000
you’ll get:
instance id’s list like:
you can easy export them and insert into your chart on CloudWatch.