Skip to main content

AWS CLI

AWS CLI 소개

AWS CLI를 사용하면 명령줄을 사용하여 서비스를 관리하고 스크립트를 통해 서비스를 제어할 수 있습니다. 많은 사용자가 AWS CLI를 사용하여 일정 수준의 자동화를 수행합니다.

EC2 인스턴스에 연결하고 다음 명령을 붙여넣습니다. 머신에 이미 AWS CLI가 설치되어 있지만 이렇게 하면 업데이트가 시작됩니다. 설치 방법에 따라 이를 확인하는 몇 가지 방법이 있습니다. (아래는 몇가지 예시임)

dpkg --list | grep awscli
pip3 list | grep awscli

AWS CLI 사용

다음 명령을 사용하여 AWS CLI를 탐색합니다(창을 종료하려면 q를 사용하세요):

  • version
  • general AWS CLI help
  • help related to Amazon EC2 commands
  • the list of your existing instances with their key characteristics
  • the list of your registered SSH key-pairs
aws --version

예) Cloud9 에서는 기본적으로 AWS CLI가 설치되어 있습니다.

Screenshot 2023-10-18 at 12.05.36 PM.png

aws help
aws ec2 help
aws ec2 describe-instances
aws ec2 describe-key-pairs

위의 describe-instancesdescribe-key-pairs 명령은 AWS 계정의 자격 증명인 액세스 키와 리전을 설정하지 않았기 때문에 실패할 가능성이 높습니다. EC2, S3 등과 같은 AWS 리소스에 액세스하려면 자격 증명이 필요하므로 권한 오류가 발생합니다(자격 증명이 없으면 AWS CLI는 사용자가 참조하는 계정을 알 수 없음). aws configure 명령을 사용하여 수동으로 입력할 수 있습니다.

아직 AWS 계정의 자격 증명으로 인스턴스를 구성하지 않았으므로 ~/.aws/ 폴더를 사용할 수 없습니다. 이제 aws configure를 진행하겠습니다.

계정 설정 (워크샵 스튜디오 사용자)

AWS 에서 제공하는 워크샵 스튜디오 환경에서 실습을 할 경우는 아래와 같이 사전에 준비된 Credential을 사용하면 됩니다. 만일 그렇지 않을 경우 Access Key 를 만드는 방법은 다음 링크를 참고하세요.

Screenshot 2023-09-27 at 10.52.34 AM.png

Screenshot 2023-09-27 at 10.52.25 AM copy.png

터미널 창에 바로 Copy & Paste 할 수 있습니다.

이제 다시 한번 aws ec2 describe-key-pairs 명령어를 입력해보세요.

Untitled.png

계정 설정 (일반 AWS 계정 사용자)

워크샵 스튜디오 환경에서 진행할 경우 아래 내용을 따라갈 필요는 없습니다!

Configuration

  1. Run the aws configure command명령 실행
aws configure
  1. Enter계정의 yourAWS account’s액세스 aws accessID를 key id입력합니다.
aws_access_key_id=[Access Key ID]
  1. Enter계정의 yourAWS account’s비밀 aws액세스 secret키를 access key입력합니다.
aws_secret_access_key=[Secret Access Key]
  1. Enter기본 a지역 default이름을 region name입력합니다. For the워크샵이 purposes실행되는 of리전에 this따라 workshop,설정합니다. use여기서는 예로써 us-east-1 (the미국 region동부 for지역)을 US East)사용합니다.
Default region name=us-east-1

HitEnter enter키를 to눌러 accept출력 the형식의 defaults기본값을 for output format수락합니다.

  1. Run the ec2 describe-instances command명령을 and실행하고 check출력을 the output.확인합니다.
aws ec2 describe-instances

This여기에는 gives지정된 a지역에 description대한 of계정의 all the모든 EC2 instances인스턴스에 in대한 the설명이 account for the specified region.표시됩니다.

  1. In또한 addition,선택한 take지역에 a대한 look at쌍을 the key-pairs we have for the selected region.살펴보세요.
aws ec2 describe-key-pairs

Note: This is a very brief introduction to이것은 AWS CLI.CLI에 With대한 great매우 power간략한 comes소개입니다. great막강한 responsibility,힘에는 so막중한 familiarise책임이 yourself따르므로 and인스턴스 practice자동화에 before사용하기 using전에 it충분히 to숙지하고 automate연습하세요. instances. Your wallet will thank you.

Next, you will use the AWS CLI to interact with Amazon S3.

Verifying AWS Credentials

Before we interact with the Amazon S3S3와 let상호 us작용하기 take a look at the importance of the전에 AWS credentials.

자격

증명의 중요성에 대해 살펴보겠습니다. AWS security보안 credentials자격 are증명은 used다음을 to확인하는 verify데 사용됩니다.

  1. Who사용자가 you are누구인지
  2. YourAWS에 permission요청하는 to리소스에 access액세스할 the resources있는 that권한은 you이러한 are보안 requesting
    AWS자격 uses증명을 these사용하여 security요청을 credentials인증하고 to권한을 authenticate and authorize your requests.부여합니다.

We이전 configured섹션에서 who사용자를 you구성했습니다. are이제 in the earlier section. Let us inspect the credentials and config files in the ~/.aws/ folder폴더에 now.있는 자격 증명과 구성 파일을 살펴보겠습니다. (Not워크샵스튜디오를 applicable for사용한 AWS configure구성에는 with적용되지 Event않음) Engine code snippet)

cat ~/.aws/credentials
cat ~/.aws/config

이제

IMPORTANT:사용자 If신원을 you성공적으로 are using Event Engine for this workshop, make sure to have the AWS ACCESS KEY ID, AWS SECRET ACCESS KEY, AWS DEFAULT REGION match the temporary account’s credentials from the Console page on Event Engine. The AWS SESSION TOKEN is unique for each Event Engine session (this session token is NOT APPLICABLE for an original AWS account)구성했습니다.

We now successfully configured who you are. Next, we will configure your permission to access the resources that you are requesting (i.e. with a “named profile”) to interact with Amazon S3.

 

참고자료