ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • AWS cli - shell script (access key 사용하지 않음)
    카테고리 없음 2024. 9. 12. 16:01

    상황

     

    계정 A 에서 AWS CLI 를 통해 계정 B와 계정 C의 RDS 수정 필요

     

    cross-account role 은 설정해둔 상태

    - 확인 : aws rds describe-db-instances --profile @@@ (계정 A와 B의 assume-role profile)

     

    config 파일

    aws configure --profile @@@ 
    access key 를 사용하지 않을 경우엔 위처럼 생성해도 access key 와 secret key 를 입력하지 않으면
    ~/.aws/config 파일에 profile 계정이 존재하지 않음
    
    따라서 직접 입력하는게 편함
    
    vi ~/.aws/config 
    
    [profile @@@]
    role_arn = arn:aws:iam::~~~~~~ // cross account role 의 arn 입력
    credential_source = Ec2InstanceMetadata // ec2 를 통해 계정 B의 서비스(ec2/rds 등등)에 접근
    output = text (json | text)
    region = ~~~~~~~ (사용하는 리전)

     

    credentials 파일

    위 방법으로 계정을 생성하면 credentials 파일에는 아무것도 없음 ( access key 를 등록하지 않고 profile 생성했기 때문)

     

    이렇게 생성하고 shell script 로 계정 B 또는 C의 RDS 를 수정하려 했으나 불가

     

    오류 : The config profile ({계정명}) could not be found

     

    해결 과정

    1. 권한 문제는 당연히 아니겠지만 추가 및 수정

    해당 Role 에 Full 권한을 줬음에도 오류 발생

     

    2. Role 인증(?) 문제 ?

    aws rds modify~~~~ --profile @@@ 를 입력하면 정상 실행

    shell script 에서 modify 는 실행을 못하는건가 생각함

    그래도 다시

    위에서 config, credentials 에서 설정한 부분을 주석처리 후 계정 B에서 access-key 발급

    계정 A의 ec2에서 프로필 재생성

    aws configure --profile @@@ 를 통해 access key, secret key 입력 후 config, credentials 에 새로 등록된 프로필 확인

    다시 shell script 구동 - 동일한 오류

     

    3. 스크립트 수정

    config 에서 못 찾고 있다 라고 생각했으나.. 스크립트에서 문제

    추후에 profile 이 변경될 경우를 생각해 profile 변수 선언

    profile_B=B_switch

    (계정 B에 접근할 profile 이며 ~/.aws/config 파일과 동일)

     

    기존 스크립트

    aws rds modify-db-instance --db-instance-identifier ${profile_b_rds_modify} --preferred-maintenance-window ${day_time} --region ${region} --profile ${profile_B}

     

    수정 스크립트

    aws rds modify-db-instance --db-instance-identifier ${profile_b_rds_modify} --preferred-maintenance-window ${day_time} --region ${region} --profile $profile_B

    로 수정하고 됨..

     

    {변수} 가 습관이였는데 ㅠㅠ 

     

     

Designed by Tistory.