# AWS AssumeRole 설정하기
1. AccessKey와 SecretKey 설정하기
보통 계정 아이디 폴더 밑에 .aws 폴더가 아래와 같이 생기고 해당 폴더에는 아래와 같이 config 파일과 credentials파일이 존재한다.
config 파일은 리전과 아웃풋 타입 등의 내용을 입력해 놓는다.
credentials 파일과 같은 경우는 aws_access_key_id 와 aws_secret_access_key를 입력한다.
2. 예제 구성 (profile 추가)
예를 들면 아래와 같이 구성하면 된다.
AWS 공식 가이드 : https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/cli-configure-files.html
구성 및 자격 증명 파일 설정 - AWS Command Line Interface
초기 키 페어 생성 중에 .csv 파일 다운로드(Download .csv file) 대화 상자를 닫으면 대화 상자를 닫은 후 비밀 액세스 키에 액세스할 수 없습니다. .csv 파일이 있어야 하는 경우 필요한 헤더와 저장된
docs.aws.amazon.com
~/.aws/credentials
[default]
aws_access_key_id=AAAAAAAAAAAAAAAAAAAABBBBBBBBBBB
aws_secret_access_key=w+asdwasfsadsadwasdwasdwasdwasd
# 다른 자격증명 등록
[user1]
aws_access_key_id=BBBBBBBBBBASDAWSDASDAWSDWASDWAS
aws_secret_access_key=saldkosadwkpasodpasdpwoaskdwpas
~/.aws/config
[default]
region=us-west-2
output=json
# 웨에서 등록한 profile 추가
[profile user1]
region=us-east-1
output=text
현재 설정된 자격 증명 확인 (현재 어떤 자격증명을 사용하고 있는지 확인 가능)
aws sts get-caller-identity
config 파일에 role_arn 설정
[profile role]
source_profile = default
mfa_serial = arn:aws:iam::xxxxxxxxxxxxx:mfa/사용자명
role_arn = arn:aws:iam::yyyyyyyyyyyy:role/역할명
3. profile 설정
profile 전환
export AWS_PROFILE=user1
4. 추가 설정 사항
aws 설정된 지역 확인
aws configure get region
profile 설정 관련 aws 공식 가이드는 아래와 같다.
https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/cli-configure-profiles.html
구성 및 자격 증명 파일 설정 - AWS Command Line Interface
AWS CLI는 config 파일에서 보안 인증을 읽을 수 있으므로 모든 프로파일 설정을 단일 파일에 보관할 수 있습니다. 동일한 이름을 공유하는 프로파일에 대한 보안 인증이 두 파일 모두에 있는 경우
docs.aws.amazon.com
region 설정 관련 내용은 아래와 같다.
aws ec2 describe-key-pairs
aws ec2 describe-key-pairs --region ap-northeast-2
output 설정 옵션은 아래와 같다.
aws 공식 가이드 : https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output-format.html
Set the AWS CLI output format - AWS Command Line Interface
If you output text, and filter the output to a single field using the --query parameter, the output is a single line of tab-separated values. To get each value onto a separate line, you can put the output field in brackets, as shown in the following exampl
docs.aws.amazon.com
CLI 옵션은 아래와 같다.
https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/cli-configure-options.html
명령줄 옵션 - AWS Command Line Interface
명령줄 옵션 AWS CLI에서 명령줄 옵션은 기본 구성 설정, 해당 프로파일 설정 또는 해당 단일 명령에 대한 환경 변수 설정을 재정의하는 데 사용할 수 있는 전역 파라미터입니다. 명령줄 옵션을 통
docs.aws.amazon.com
5. Assume Role 정리 (Login)
profile 설정
# SSO 관련 Profile
SET AWS_PROFILE=DEV-ACCOUNT
aws sso login --profile DEV-ACCOUNT
# USER 계정정보
SET AWS_PROFILE=DEV-USER
# 권한 확인
aws sts get-caller-identity
- 끝 -
'⭐ AWS > 🔑 AWS Account (AssumeRole, STS)' 카테고리의 다른 글
aws configure sso (0) | 2024.01.31 |
---|