AWS

AWS CLI 정리

Somaz 2023. 3. 31. 20:00
728x90
반응형

Overivew

오늘은 AWS CLI(Command Line Interface)에 대해 정리해보았다.


AWS CLI는 AWS 리소스를 명령어 기반으로 관리할 수 있도록 도와주는 강력한 도구로, GUI 없이도 다양한 작업을 자동화하거나 빠르게 수행할 수 있게 해준다.

이번 글에서는 AWS CLI의 설치 방법부터 aws configure 명령을 통한 프로파일 설정, 그리고 자주 사용되는 EC2, S3, IAM, ECR, EKS 명령어들을 실습 중심으로 정리하였다.


CLI 기반의 인프라 관리를 시작하고자 하는 분들에게 도움이 되는 실용적인 명령어 모음이 되기를 바란다.

 

 

https://dev.classmethod.jp/articles/create-application-load-balancer-with-aws-cli/

 

 

 

📅 관련 글

2022.02.13 - [AWS] - AWS IAM (Identity and Access Management) 개요 및 설정 방법

2022.02.07 - [AWS] - AWS EC2 인스턴스 생성

2022.02.13 - [AWS] - AWS S3 (Simple Storage Service) 개요 및 활용 방법

2023.03.30 - [AWS] - AWS Secrets Manager란?(OAuth, SSO)

2023.03.29 - [AWS] - AWS CLI 정리

2023.03.28 - [AWS] - AWS IAM이란?

2023.03.28 - [AWS] - AWS S3 권한이란?

2023.03.28 - [AWS] - AWS S3란?(개념, 속성)

2023.03.30 - [AWS] - AWS Cloudfront란? / Canary 및 Blue-Green 배포

2023.04.03 - [AWS] - AWS VPC란?

2023.05.26 - [AWS] - AWS IRSA(IAM Roles for Service Accounts)란?

2024.11.07 - [AWS] - AWS Ingress Annotations 정리

2024.11.04 - [AWS] - AWS Assume Role이란?

2024.11.16 - [AWS] - AWS Network ACL vs Security Group

2024.11.21 - [AWS] - ALB access Log 활성화 → S3 권한 설정 및 로그 저장

2024.11.24 - [AWS] - EKS Pod Identity Addon

2024.11.27 - [AWS] - AWS DynamoDB란?

2025.01.03 - [AWS] - AWS DynamoDB Local 설치

 

 

 

 

 

 


 

 

 

awscli 설치

# Version 2 설치 방법

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
$ ./aws/install -i /usr/local/aws-cli -b /usr/local/bin
$ aws --version
$ aws-cli/2.11.15 Python/3.11.3 Linux/5.15.90.1-microsoft-standard-WSL2 exe/x86_64.ubuntu.22 prompt/off

# 기존 awscli 업데이트 방법

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update

# 업그레이드 성공!
somaz@AD01769994:~$ aws --version
aws-cli/2.11.6 Python/3.11.2 Linux/5.10.16.3-microsoft-standard-WSL2 exe/x86_64.ubuntu.20 prompt/off

 

 

 

 

 

 


 

 

 

aws configure 구성

 

 

계정이 한개일 때(default)

$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: <Enter> or ex. ap-northeast-2
Default output format [None]: <Enter>

 

 

 

계정이 2개 이상일때

$ aws configure --profile <ID>
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: <Enter> or ex. ap-northeast-2
Default output format [None]: <Enter>

 

 

 

`aws configure` 구성 확인

somaz@AD01769994:~$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************MPLE shared-credentials-file
secret_key     ****************MPLG shared-credentials-file
    region           ap-northeast-2      config-file    ~/.aws/config

somaz@AD01769994:~$ aws configure list --profile somaz
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                    luxon           manual    --profile
access_key     ****************MPLE shared-credentials-file
secret_key     ****************MPLG shared-credentials-file
    region                <not set>             None    None

 

 

 

 

 


 

 

자주쓰는 AWS CLI 명령어

 

 

 

 

 


 

 

 

 

 

 

AWS EC2 (Elastic Compute Cloud)

 

 

List instances

aws ec2 describe-instances

# profile 사용하기
aws ec2 describe-instances --profile <ID>

 

 

Start an instance

aws ec2 start-instances --instance-ids <instance id>

 

 

Stop an instance

aws ec2 stop-instances --instance-ids <instance id>

 

Terminate an instance

aws ec2 terminate-instances --instance-ids <instance id>

 

 

 

 


 

 

 

 

 

 

AWS S3 (Simple Storage Service)

 

 

List buckets

aws s3 ls

 

 

List objects in a bucket

aws s3 ls s3://<bucket-name>

 

 

Copy a file to a bucket

aws s3 cp <local-file> s3://<bucket-name>/<object-name>

 

 

Copy a directory to a bucket

aws s3 cp <local-file> s3://<bucket-name>/<directory-name> --recursive

 

 

Copy a file from a bucket

aws s3 cp s3://<bucket-name>/<object-name> <Name to save to local>

 

 

Copy a directory from a bucket

aws s3 cp s3://<bucket-name>/<directory-name> <Name to save to local>  --recursive

 

 

Delete an object from a bucket

aws s3 rm s3://<bucket-name>/<object-name>

 

 

 

 

 


 

 

 

 

 

 

AWS IAM (Identity and Access Management)

 

 

List users

aws iam list-users

 

 

List roles

aws iam list-roles

 

 

Create a user

aws iam create-user --user-name <user-name>

 

 

Attach a policy to a user

aws iam attach-user-policy --user-name <user-name> --policy-arn <policy-arn>

 

 

Delete a user

aws iam delete-user --user-name <user-name>

 

 

 

 

 

 


 

 

 

 

 

 

AWS ECR (Elastic Container Registry)

 

 

List repositories

aws ecr describe-repositories

 

 

Create a repository

aws ecr create-repository --repository-name <repository-name>

 

 

Delete a repository

aws ecr delete-repository --repository-name <repository-name>

 

 

Get the login command for a registry

aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <aws-account-id>.dkr.ecr.<region>.amazonaws.com

 

 

 

 

 

 


 

 

 

 

 

 

 

AWS EKS (Elastic Kubernetes Service)

 

 

List clusters

aws eks list-clusters

 

 

Describe a cluster

aws eks describe-cluster --name <cluster-name>

 

 

Create a cluster

aws eks create-cluster --name <cluster-name> --role-arn <role-arn> --resources-vpc-config subnetIds=<subnet-id1>,<subnet-id2>

 

 

Delete a cluster

aws eks delete-cluster --name <cluster-name>

 

 

 

 

 


 

 

 

 

마무리

AWS CLI는 단순한 명령어 도구를 넘어서, 반복 작업 자동화, 스크립트 기반 운영, CI/CD 파이프라인 연동 등 다양한 활용이 가능하다.
GUI보다 CLI를 능숙하게 다루면 리소스 관리 속도도 빨라지고, 실수도 줄일 수 있다.

 

특히 오늘 정리한 EC2 인스턴스 제어, S3 파일 조작, IAM 사용자 관리, ECR 레지스트리 연동, EKS 클러스터 관리 등은 실무에서 자주 활용되는 만큼 꼭 익혀두길 추천한다.

 

앞으로는 aws cli를 활용해 ALB(Application Load Balancer), CloudWatch, Route53 등 더 다양한 AWS 서비스 자동화도 소개해볼 예정이다.

 


꾸준히 실습하며 익히면 AWS 운영의 효율성과 생산성이 분명히 높아질 것이다

 

 

 

 

 

 

 

 

 


Reference

What is AWS Command Line Interface?

 

AWS CLI Command Reference

 

AWS CLI로 Application Load Balancer 생성해 보기

 

 

 

 

 

 

728x90
반응형

'AWS' 카테고리의 다른 글

AWS Cloudfront란? / Canary 및 Blue-Green 배포  (0) 2023.04.03
AWS Secrets Manager란?(OAuth, SSO)  (0) 2023.04.01
AWS IAM이란?  (0) 2023.03.30
AWS S3 권한이란?  (0) 2023.03.29
AWS S3란?(개념, 속성)  (0) 2023.03.28