개발일기

AWS - AWS CLI로 인증 정보 관리하기 본문

Web 서비스/AWS

AWS - AWS CLI로 인증 정보 관리하기

Flashback 2023. 1. 13. 22:16
728x90
반응형

1. AWS CLI 패키지 설치

AWS CLI 패키지를 설치하여 access key와 secret key를 입력하여 인증 정보를 저장하여 간편하게 사용할 수 있다.

sudo yum install awscli
# CentOs

sudo apt install awscli
# Ubuntu

 

2. 인증 정보 추가

aws configure

쉘에서 aws configure를 입력하면 access key, secret key, region, output format 순으로 입력을 하게된다.

AWS 계정의 IAM 사용자의 access key, secret key, region 정보를 입력하면된다. 마지막으로 output format은 IAM 사용자 목록을 출력할 때, 표시할 형식을 지정할 수 있다. output format의 옵션에는 json, yaml, yaml-stream, text, table이 있다. output format 옵션은 기본값이 json으로 설정되기에 옵션을 생략하고 엔터를 눌러도 무관하다.

 

2-1. 프로필명 추가

aws cli는 프로필명을 추가하여 다수의 IAM 사용자를 등록하여 서로 다른 권한을 가진 사용자를 시기적절하게 교체하여 사용할 수 있다. 또는 다수의 프로젝트를 진행할 때, 프로필을 변경하여 해당 프로젝트의 적합한 IAM 사용자로 테스트를 진행할 수 있다.

프로필명을 추가하지않고 인증 정보를 추가한 경우, 프로필명은 default로 설정되어 인증 정보가 저장된다.

aws configure --profile mango

# aws configure --pofile [프로필명]

--profile [프로필명]을 추가해주면 프로필명을 지정한채로 인증 정보를 저장할 수 있다. 위와 같이 입력하면 프로필명은 mango로 설정된채로 access key, secret key, region, output format을 입력하여 인증 정보를 저장할 수 있다.

 

3. 인증 정보 목록 확인

aws configure list

현재 설정된 인증 정보가 나타난다.

access key와 secret key는 가려진채로 출력된다. region은 ap-northeast-2, ap-northeast-1 등으로 설정한 옵션에 따라 출력된다.

만약 2-1과 같이 default외에도 추가로 프로필명을 지정하여 추가한 인증 정보가 나오지 않아 의아하게 느껴질 수도 있다. default값이 나오는 현재 사용할 인증 정보를 default로 지정하였기 때문에 mango의 값이 나오지 않는 것이다. export AWS_PROFILE~을 사용하여 프로필을 지정하여 프로젝트에 따라 변경시킬 수 있다.

 

4. 인증 정보 저장 폴더

aws cli 인증 정보가 저장되어있는 파일을 통해 직접적으로 인증 정보를 추가하거나 삭제할 수 있다.

cd
# 쉘에서 cd를 입력하여 루트 경로로 이동한다.

vi .aws/config
# 프로필에 따른 output, region 정보 수정

vi .aws/credentials
# 프로필에 따른 aws_access_key, aws_secret_access_key 정보 수정

.aws/credentials
.aws/config

에디터로 실행시킨 config와 credentials 파일을 실행하여 프로필과 인증 정보를 직접 수정할 수 있다.

 

5. 프로필 교체

default와 mango 두개의 프로필이 있는 상태에서 mango라는 프로필을 사용하여 프로젝트를 진행하고자 할 때 export AWS_PROFILE 을 사용하여 현재 설정된 프로필을 mango로 교체할 수 있다.

export AWS_PROFILE=mango
# 프로필을 mango로 교체

export AWS_PROFILE=default
# 프로필을 default로 교체

프로필을 mango로 교체하고 aws configure list를 실행하면 프로필이 mango로 바뀌어 access key, secret key, region 정보가 나오는 것을 확인할 수 있다.

프로필이 mango로 변경되었다.

 


참고 사이트 : 

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html

 

What is the AWS Command Line Interface? - AWS Command Line Interface

What is the AWS Command Line Interface? The AWS Command Line Interface (AWS CLI) is an open source tool that enables you to interact with AWS services using commands in your command-line shell. With minimal configuration, the AWS CLI enables you to start r

docs.aws.amazon.com

 

https://linuxhint.com/install_aws_cli_ubuntu/

 

Install AWS Command Line Interface (CLI) on Ubuntu 22.04 LTS

AWS CLI or Amazon Web Service Command Line Interface is a command-line tool for managing and administering your Amazon Web Services. AWS CLI provides direct access to the public API (Application Programming Interface) of Amazon Web Services. Since it’s a

linuxhint.com

 

https://stackoverflow.com/questions/593334/how-to-use-multiple-aws-accounts-from-the-command-line

 

How to use multiple AWS accounts from the command line?

I've got two different apps that I am hosting (well the second one is about to go up) on Amazon EC2. How can I work with both accounts at the command line (Mac OS X) but keep the EC2 keys &

stackoverflow.com

 

https://stackoverflow.com/questions/49716583/how-to-temporarily-switch-profiles-for-aws-cli

 

How to temporarily switch profiles for AWS CLI?

Updated answer (7/10/2021): For AWS CLI v1, do this: export AWS_DEFAULT_PROFILE=user2 For AWS CLI v2, the following will work: export AWS_PROFILE=user2 The full question is below for context: (1.)

stackoverflow.com

 

728x90
반응형

'Web 서비스 > AWS' 카테고리의 다른 글

AWS - RDS(Relational Database Service)란?  (0) 2022.05.24
AWS - EC2(Elastic Compute Cloud)란?  (0) 2022.05.20
AWS - IAM(Identity and Access Management)란?  (0) 2022.05.20
AWS S3에 파일 업로드  (0) 2021.05.31
Comments