AWS CLI
AWS CLI 소개
AWS CLI를 사용하면 명령줄을 사용하여 서비스를 관리하고 스크립트를 통해 서비스를 제어할 수 있습니다. 많은 사용자가 AWS CLI를 사용하여 일정 수준의 자동화를 수행합니다.
EC2 인스턴스에 연결하고 다음 명령을 붙여넣습니다. 머신에 이미 AWS CLI가 설치되어 있지만 이렇게 하면 업데이트가 시작됩니다. 설치 방법에 따라 이를 확인하는 몇 가지 방법이 있습니다. (아래는 몇가지 예시임)
dpkg --list | grep awscli
pip3 list | grep awscli
기존 Amazon EC2 인스턴스에서 확인
다음 명령을 사용하여 AWS CLI를 탐색합니다(창을 종료하려면 q를 사용하세요):
- 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 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 Configure - General Use
참고: 위에서 처럼
- Run the aws configure command
aws configure
- Enter your account’s aws access key id
aws_access_key_id=[Access Key ID]
- Enter your account’s aws secret access key
aws_secret_access_key=[Secret Access Key]
- Enter a default region name. For the purposes of this workshop, use ap-southeast-1 (the region for Singapore).
Default region name=ap-southeast-1
Hit enter to accept the defaults for output format
- 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.
- 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. 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 S3 let us take a look at the importance of the AWS credentials.
AWS security credentials are used to verify
- Who you are
- Your 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.