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가 설치되어 있습니다.
aws help
aws ec2 help
aws ec2 describe-instances
aws ec2 describe-key-pairs
위의 describe-instances
및 describe-key-pairs
명령은 AWS 계정의 자격 증명인 액세스 키와 리전을 설정하지 않았기 때문에 실패할 가능성이 높습니다. EC2, S3 등과 같은 AWS 리소스에 액세스하려면 자격 증명이 필요하므로 권한 오류가 발생합니다(자격 증명이 없으면 AWS CLI는 사용자가 참조하는 계정을 알 수 없음). aws configure
명령을 사용하여 수동으로 입력할 수 있습니다.
아직 AWS 계정의 자격 증명으로 인스턴스를 구성하지 않았으므로 ~/.aws/ 폴더를 사용할 수 없습니다. 이제 aws configure를 진행하겠습니다.
계정 설정 (워크샵 스튜디오 사용자)
AWS 에서 제공하는 워크샵 스튜디오 환경에서 실습을 할 경우는 아래와 같이 사전에 준비된 Credential을 사용하면 됩니다. 만일 그렇지 않을 경우 Access Key 를 만드는 방법은 다음 링크를 참고하세요.
터미널 창에 바로 Copy & Paste 할 수 있습니다.
이제 다시 한번 aws ec2 describe-key-pairs
명령어를 입력해보세요.
계정 설정 (일반 AWS 계정 사용자)
워크샵 스튜디오 환경에서 진행할 경우 아래 내용을 따라갈 필요는 없습니다!
Configuration
Run theaws configurecommand명령 실행
aws configure
Enter계정의yourAWSaccount’s액세스aws키accessID를key id입력합니다.
aws_access_key_id=[Access Key ID]
Enter계정의yourAWSaccount’s비밀aws액세스secret키를access key입력합니다.
aws_secret_access_key=[Secret Access Key]
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수락합니다.
Run theec2 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.표시됩니다.
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이것은 AWSCLI.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데 사용됩니다.
Who사용자가you are누구인지YourAWS에permission요청하는to리소스에access액세스할the수resources있는that권한은you이러한are보안requestingAWS자격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 theAWS ACCESS KEY ID,AWS SECRET ACCESS KEY,AWS DEFAULT REGIONmatch the temporary account’s credentials from the Console page on Event Engine. TheAWS SESSION TOKENis 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.