카테고리 없음

AWS에서 도쿄 리전(ap-northeast-1)에 사용 중인 주요 서비스의 리소스를 체크하는 간단한 Bash 스크립트

idea9329 2024. 9. 3. 14:56
반응형

아래는 AWS에서 도쿄 리전(ap-northeast-1)에 사용 중인 주요 서비스의 리소스를 체크하는 간단한 Bash 스크립트입니다. 이 스크립트는 EC2, S3, RDS, Lambda, CloudFormation, ELB, VPC, ECS 등의 리소스를 확인합니다.

#!/bin/bash

REGION="ap-northeast-1"

echo "Checking AWS resources in region: $REGION"

# EC2 인스턴스
echo "Checking EC2 Instances..."
aws ec2 describe-instances --region $REGION --query "Reservations[].Instances[].InstanceId" --output text

# S3 버킷 (S3는 리전 개념이 없으나, 버킷 위치를 확인할 수 있음)
echo "Checking S3 Buckets..."
aws s3api list-buckets --query "Buckets[].Name" --output text | while read bucket; do
    location=$(aws s3api get-bucket-location --bucket $bucket --query "LocationConstraint" --output text)
    if [ "$location" == "ap-northeast-1" ] || [ "$location" == "null" ]; then
        echo "Bucket: $bucket, Location: $location"
    fi
done

# RDS 인스턴스
echo "Checking RDS Instances..."
aws rds describe-db-instances --region $REGION --query "DBInstances[].DBInstanceIdentifier" --output text

# Lambda 함수
echo "Checking Lambda Functions..."
aws lambda list-functions --region $REGION --query "Functions[].FunctionName" --output text

# CloudFormation 스택
echo "Checking CloudFormation Stacks..."
aws cloudformation describe-stacks --region $REGION --query "Stacks[].StackName" --output text

# ELB
echo "Checking Elastic Load Balancers (ELB)..."
aws elb describe-load-balancers --region $REGION --query "LoadBalancerDescriptions[].LoadBalancerName" --output text

# VPC
echo "Checking VPCs..."
aws ec2 describe-vpcs --region $REGION --query "Vpcs[].VpcId" --output text

# ECS 클러스터
echo "Checking ECS Clusters..."
aws ecs list-clusters --region $REGION --query "clusterArns[]" --output text

echo "AWS resource check completed."

스크립트 설명:

  • REGION 변수: REGION 변수를 설정하여, 도쿄 리전(ap-northeast-1)에서 리소스를 검색하도록 지정합니다.
  • 서비스별로 리소스 확인: 각 서비스에 대해 AWS CLI 명령어를 사용하여 현재 사용 중인 리소스를 나열합니다.
  • S3 버킷 위치 확인: S3 버킷은 리전 개념이 없지만, get-bucket-location 명령을 사용하여 버킷의 위치가 도쿄 리전인지 확인합니다.
  • 출력 형식: 결과는 텍스트 형식으로 출력됩니다. 필요에 따라 출력 형식을 변경할 수 있습니다.

스크립트 실행 방법:

  1. 스크립트를 파일로 저장합니다. 예를 들어 check_aws_resources.sh로 저장합니다.
  2. 스크립트에 실행 권한을 부여합니다:
    chmod +x check_aws_resources.sh
  3. 스크립트를 실행합니다:
    ./check_aws_resources.sh

이 스크립트는 도쿄 리전에서 사용 중인 주요 AWS 리소스를 나열하는 데 유용합니다. 필요에 따라 추가적인 서비스나 리소스를 확인하는 명령어를 스크립트에 추가할 수 있습니다. 예를 들어, DynamoDB 테이블, CloudWatch 로그 그룹 등을 추가할 수 있습니다.

반응형