AWS ECS service last event

2022. 10. 12. 15:41기타/scripts

728x90
SMALL

- 개요

ECS의 Service의 상태를 확인하는 가장 효과적인 방법은 최근 event 를 확인하는 것이다. 아래는 사용하고 있는 전체 ECS Service의 마지막 event log를 확인하는 스크립트 이다.

 

 

- 스크립트

#!/bin/bash
declare -a ecscluster=$(aws ecs list-clusters | awk -F / '{print $2}' | tr -d '",' | awk NF)
region=`aws configure get profile.default.region`

for i in ${ecscluster[@]}
do
        for service in $(aws ecs list-services --cluster $i | awk -F / '{print $3}' | tr -d '",' | awk NF)
                do
                        echo "Cluster: $i, Service: $service"
                        echo "####################################################################################################################################################################################"
                        aws ecs describe-services --services $service --region $region --cluster $i --query 'services[*].events[:5]' --output text
                        echo "####################################################################################################################################################################################"
                done
done

 

728x90
LIST