AWS CLI 정리
실무에서 자주 사용되는 AWS CLI를 정리하기 위한 목적으로 포스팅을 작성한다.
01. S3
AWS S3 버킷 용량 조회
# GB 단위로 특정 버킷의 용량 조회
aws s3api list-objects-v2 \
--bucket <버킷명> \
--prefix <prefix> \
--query "sum(Contents[].Size)" \
--output text | awk '{printf "%.2f GB\\n", $1 / 1024 / 1024 / 1024}'
AWS S3 재귀 파일 다운로드
# aws s3 cp s3://<버킷 경로>/ <다운로드 받을 위치> --recursive
02. EC2(Elastic Compute Cloud)
EC2 인스턴스 시작
aws ec2 start-instances \\
--instance-ids <instance-id>
EC2 인스턴스 정보 조회
aws ec2 describe-instances \
--filters "Name=tag:<태그명>,Values=<값>" \
--no-cli-pager \
--query "Reservations[].Instances[].{
InstanceID: InstanceId,
AMI: ImageId,
State: State.Name,
Name: Tags[?Key=='Name'].Value | [0],
CreatedBy: Tags[?Key=='createdby'].Value | [0],
Env: Tags[?Key=='env'].Value | [0]
}" \
--output table
EC2 태그 목록 조회
aws ec2 describe-instances \
--filters "Name=tag:<태그명>,Values=<값>" \
--no-cli-pager \
--query "Reservations[].Instances[].{
Env: Tags[?Key=='env'].Value | [0],
CreatedBy: Tags[?Key=='createdby'].Value | [0],
InstanceID: InstanceId,
AMI: ImageId,
State: State.Name,
Name: Tags[?Key=='Name'].Value | [0]
}" \
--output table
EC2 인스턴스 종료
aws ec2 terminate-instances --instance-ids <instance id>
03. ECS(Elastic Container Service)
ECS 클러스터 태그 정보 조회
aws ecs describe-clusters \
--include TAGS \
--clusters <ECS 클러스터명>
ECS 서비스 태그 정보 조회
aws ecs list-tags-for-resource \
--resource-arn arn:aws:ecs:ap-northeast-2:<account>:service/<클러스터명>/<서비스명> \
--output table
ECS TOP 20 Task Definitions 정보 조회
aws ecs list-task-definitions \
--family-prefix <task definitions> \
--sort DESC | jq -r ".taskDefinitionArns[:20]"
ECS Task Definitions 상세 정보 조회
aws ecs describe-task-definition \
--no-cli-pager \
--task-definition <task definitions> | jq
ECS Task Definitions 신규 등록
aws ecs register-task-definition \
--no-cli-pager \
--cli-input-json file://<task definitions 이름 기재>
ECS 서비스 조회
aws ecs describe-services \
--no-cli-pager \
--cluster <클러스터명> \
--services <서비스명>
04. ECR(Elastic Container Registry)
ECR 특정 리포지토리 태그 추가
aws ecr tag-resource \
--resource-arn arn:aws:ecr:ap-northeast-2:<account>:repository/<리포지토리명> \
--tags \
Key=<Key 값>,Value=<Value 값> \
Key=<Key 값>,Value=<Value 값>
ECR 리포지토리 태그 변경 여부 설정
aws ecr put-image-tag-mutability \
--repository-name <리포지토리명> \
--image-tag-mutability <MUTABLE | IMMUTABLE>
ECR 특정 태그 이미지 삭제
aws ecr batch-delete-image \
--repository-name <리포지토리명> \
--image-ids imageTag=1.x.x
05. CodeCommit
신규 CodeCommit 리포지토리 생성
aws codecommit create-repository \\
--repository-name my-new-repo \\
--repository-description "Infra IaC 모듈 저장" \\
--tags '{"Name":"my-new-repo", "env":"prod"}'
99. 참고 자료
AWS CLI를 사용한 Amazon ECR 예제 - AWS Command Line Interface
AWS CLI를 사용한 Amazon ECR 예제 다음 코드 예제에서는 Amazon ECR에서 AWS Command Line Interface를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다. 작업은 대규모 프로그램에
docs.aws.amazon.com
'Public Cloud > AWS - Practice' 카테고리의 다른 글
| [AWS] ECS Network Mode (0) | 2025.07.30 |
|---|---|
| [AWS] Lambda + EventBridge 기반 스케쥴링 (0) | 2025.07.28 |
| [AWS] 인터넷 게이트웨이 (0) | 2025.07.10 |
| [AWS] AWS VPC, Subnet IP 대역을 설정하는 기준은? (0) | 2025.06.10 |
| [AWS] 왜 Public, Private Subnet은 분리가 되어 있을까? (0) | 2025.06.09 |