Front-End/AWS

[AWS] CLI

Voyage_dev 2023. 6. 19. 02:24

AWS CLI 설치

// with brew

brew install awscli

// aws version
aws --version

CLI 인증 설정

  • AWS 계정에서 발급한 IAM 사용자의 Access Key ID / Secret Access Key 필요
aws configure

AWS Access Key ID [None] : [발급받은 IAM의 Access Key ID]
AWS Secret Access Key [None] : [발급받은 IAM의 Secret Access Key]
ap-northeast-2  = 서울
output format : json

AWS Access Key ID [None]: [여기에 AWS Access Key를 입력]
AWS Secret Access Key [None]: [여기에 AWS Secret Access Key를 입력]
Default region name [None]: [여기에 Default Region을 입력]
Default output format [None]: [여기에 output format을 입력]
  • 입력한 정보는 다음의 의미를 갖는다
    • AWS Access Key ID : default 프로필이 사용할 Access Key
    • AWS Secret Access Key : default 프로필이 사용할 Secret Access Key
    • Default region name : default 프로필이 aws cli 명령어를 사용할 때, 기본적으로 적용할 리전
    • Default output format : default 프로필을 통해 aws cli 명령어를 사용할 때, 반환된 정보의 output 형식
      • 지원되는 format은 링크를 참조할 것 :
  • 입력한 정보는 다음의 위치에 저장된다.
    • ~/.aws/configure : 각 프로필 별 리전 및 output format
    • ~/.aws/credentials : 각 프로필 별 Access Key / Secret Access Key

CLI 명령어

`cat ~/.aws/credentials` : access key 와 secret key 확인

`cat ~/.aws/config` : region / output 확인

`aws sts get-caller-identity` : 현재 자격증명

`aws configure get region` : 설정된 지역 확인

`export AWS_DEFAULT_PROFILE=default` : defaul를 원래 계정으로 설정

`export AWS_DEFAULT_PROFILE=~`  default를 부계정으로 설정

폴더 확인

ls -al

ex)

drwxr-x---+  28 jayden  staff    896  3 28 13:33 .
drwxr-xr-x    5 root    admin    160  2  1 09:22 ..
-r--------    1 jayden  staff      8  2  1 09:22 .CFUserTextEncoding
-rw-r--r--@   1 jayden  staff  12292  3 28 13:54 .DS_Store
drwx------+ 384 jayden  staff  12288  3 28 09:18 .Trash
drwxr-xr-x    4 jayden  staff    128  3  9 09:35 .aws
-rw-------    1 jayden  staff    188  3 10 11:30 .bash_history
drwxr-xr-x    4 jayden  staff    128  2  2 17:06 .config
drwxr-xr-x   10 jayden  staff    320  3 28 13:55 .console-ninja
-rw-------    1 jayden  staff     20  3 28 13:33 .lesshst
drwxr-xr-x    8 jayden  staff    256  2 25 22:01 .npm
drwxr-xr-x   27 jayden  staff    864  3 10 11:32 .nvm
-rw-------    1 jayden  staff   7259  3 10 18:13 .viminfo
drwxr-xr-x    4 jayden  staff    128  2  1 09:37 .vscode
-rw-r--r--    1 jayden  staff    116  3 28 09:35 .yarnrc
-rw-r--r--    1 jayden  staff  47799  3 10 11:31 .zcompdump
-rw-r--r--    1 jayden  staff     83  2  2 10:26 .zprofile
-rw-------    1 jayden  staff  29052  3 28 11:31 .zsh_history
drwx------    8 jayden  staff    256  3 28 13:14 .zsh_sessions
-rw-r--r--    1 jayden  staff    268  3 10 11:31 .zshenv
drwx------+  17 jayden  staff    544  3 28 13:54 Desktop
drwx------@  14 jayden  staff    448  3 28 09:18 Documents
drwx------+  22 jayden  staff    704  3 28 13:53 Downloads
drwx------@  77 jayden  staff   2464  2  6 14:39 Library
drwx------    4 jayden  staff    128  2  1 15:31 Movies
drwx------+   4 jayden  staff    128  2 22 17:53 Music
drwx------+   5 jayden  staff    160  3 20 09:42 Pictures
drwxr-xr-x+   4 jayden  staff    128  2  1 09:22 Public

.ssh폴더가 없으면

ssh
yes

ls -al

drwxr-x---+  29 jayden  staff    928  3 28 13:56 .
drwxr-xr-x    5 root    admin    160  2  1 09:22 ..
-r--------    1 jayden  staff      8  2  1 09:22 .CFUserTextEncoding
-rw-r--r--@   1 jayden  staff  12292  3 28 13:54 .DS_Store
drwx------+ 384 jayden  staff  12288  3 28 09:18 .Trash
drwxr-xr-x    4 jayden  staff    128  3  9 09:35 .aws
-rw-------    1 jayden  staff    188  3 10 11:30 .bash_history
drwxr-xr-x    4 jayden  staff    128  2  2 17:06 .config
drwxr-xr-x   10 jayden  staff    320  3 28 13:56 .console-ninja
-rw-------    1 jayden  staff     20  3 28 13:33 .lesshst
drwxr-xr-x    8 jayden  staff    256  2 25 22:01 .npm
drwxr-xr-x   27 jayden  staff    864  3 10 11:32 .nvm
drwx------    3 jayden  staff     96  3 28 13:56 .ssh
-rw-------    1 jayden  staff   7259  3 10 18:13 .viminfo
drwxr-xr-x    4 jayden  staff    128  2  1 09:37 .vscode
-rw-r--r--    1 jayden  staff    116  3 28 09:35 .yarnrc
-rw-r--r--    1 jayden  staff  47799  3 10 11:31 .zcompdump
-rw-r--r--    1 jayden  staff     83  2  2 10:26 .zprofile
-rw-------    1 jayden  staff  29052  3 28 11:31 .zsh_history
drwx------    8 jayden  staff    256  3 28 13:14 .zsh_sessions
-rw-r--r--    1 jayden  staff    268  3 10 11:31 .zshenv
drwx------+  17 jayden  staff    544  3 28 13:54 Desktop
drwx------@  14 jayden  staff    448  3 28 09:18 Documents
drwx------+  22 jayden  staff    704  3 28 13:53 Downloads
drwx------@  77 jayden  staff   2464  2  6 14:39 Library
drwx------    4 jayden  staff    128  2  1 15:31 Movies
drwx------+   4 jayden  staff    128  2 22 17:53 Music
drwx------+   5 jayden  staff    160  3 20 09:42 Pictures
drwxr-xr-x+   4 jayden  staff    128  2  1 09:22 Public

ssh 생성

.ssh

바탕화면에 있던 .pem 키 가져오기
mv ~/Desktop/{key}.pem .

ls -al (가져와있을거다)
cd .. (나가기)

실행

ssh -o ProxyCommand="ssh -i ~/.ssh/{~~가져온}.pem -W %h:%p ec2-user@{주소}" -i "~/.ssh/{~~가져온}.pem" ec2-user@{주소}

yes