AWS CLI를 사용하여IAM Identity Center 사용자의 임시 자격 증명을 얻으려면 어떻게 해야 하나요?

2분 분량
0

AWS IAM Identity Center 사용자를 위한 임시 자격 증명을 받고 싶습니다.

간략한 설명

IAM Identity Center를 사용하도록 명명된 프로필을 구성하면 $ cd ~/.aws/sso/cache 디렉터리에 JSON 파일이 생성됩니다. JSON 파일에는 get-role-credentials API와 동일한 명령을 사용하여 임시 보안 자격 증명을 가져오는 데 사용되는 JSON 웹 토큰(JWT)이 포함되어 있습니다. 액세스 토큰은 8시간 동안 유효합니다. JSON 파일의 expiresAt 타임스탬프에서 만료 시간을 확인할 수 있습니다. 만료된 토큰을 재인증하려면 get-role-credentials 명령을 사용해야 합니다.

해결 방법

AWS Command Line Interface(AWS CLI)를 사용하여 IAM Identity Center 사용자의 임시 자격 증명을 얻을 수 있습니다.

**참고:**AWS CLI 명령을 실행할 때 오류가 발생하면, AWS CLI 오류 문제 해결을 참조하세요. 또한 최신 AWS CLI 버전을 사용하고 있는지 확인하세요.

임시 자격 증명 가져오기

AWS CLI에서 다음 단계를 완료하세요.

  1. 다음과 같이 JSON 파일을 연 다음 액세스 토큰을 복사합니다.

    $ cat 535a8450b05870c9045c8a7b95870.json
    {"startUrl": "https://my-sso-portal.awsapps.com/start", "region": "us-east-1", "accessToken": "eyJlbmMiOiJBM….", "expiresAt": "2020-06-17T10:02:08UTC"}
  2. get-role-credentials AWS CLI 명령을 실행하여 IAM Identity Center 사용자의 자격 증명을 가져옵니다.

    $ aws sso get-role-credentials --account-id 123456789012 --role-name permission-set-name --access-token eyJlbmMiOiJBM…. --region enter_the_same_sso_region_same_in_the_JSON_file

    출력 예시:

    {    "roleCredentials": {
            "accessKeyId": "ASIA*************",
            "secretAccessKey": "**********************************",
            "sessionToken": "****************************************",
            "expiration": 1592362463000
        }
    }
  3. 자격 증명을 환경 변수로 구성합니다.

오류 메시지 문제 해결

"An error occurred (ForbiddenException) when calling the GetRoleCredentials operation: No access."

이 오류는 AWS CLI의 잘못된 역할 이름 때문에 발생할 수 있습니다. 역할 이름이 올바른지 확인합니다.

"An error occurred (UnauthorizedException) when calling the GetRoleCredentials operation: Session token not found or invalid."

이 오류는 세션 토큰 또는 AWS 리전이 올바르지 않기 때문에 발생합니다. AWS CLI 명령의 리전이 JSON 파일 출력의 리전과 동일한지 확인하세요.

관련 정보

IAM Identity Center 권한 세트를 사용하려면 어떻게 해야 하나요?

AWS 공식
AWS 공식업데이트됨 8달 전