단계 2: Cognito로 Identity 설정

이 단계에서는 Amazon Cognito를 사용하여 Custom OAuth2 기반 Provider를 구성합니다. 또한 AgentCore Gateway와 AgentCore Runtime에 필요한 SSM 파라미터와 IAM 역할을 생성합니다.

circle-exclamation

사전 요구 사항 배포

Cognito User Pool과 관련 리소스를 배포합니다:

# 사전 요구 사항 배포
chmod +x scripts/prereq.sh && ./scripts/prereq.sh
chevron-right🔍 이 스크립트는 무엇을 하나요?hashtag
  1. CloudFormation 스택 troubleshooting-agentcore-cognito 배포 (prerequisite/cognito.yaml)

  2. Cognito User Pool, Web Client(Authorization Code), Machine Client(Client Credentials) 생성

  3. 9개 SSM 파라미터 자동 생성 (/app/troubleshooting/agentcore/*)

  4. Gateway IAM 실행 역할 생성

  5. 테스트 사용자 생성 (test@example.com / TestPassword123!)

필요한 패키지를 설치합니다:

pip install -r requirements.txt

Amazon Cognito Provider 생성

AgentCore Identity에 Cognito Provider를 등록합니다:

# Amazon Cognito Provider 생성
python3 scripts/cognito_credentials_provider.py create-provider

# 프로바이더 생성 검증
python3 scripts/cognito_credentials_provider.py list-providers
chevron-right🔍 이 스크립트는 무엇을 하나요?hashtag
  1. SSM에서 Cognito Machine Client ID와 Secret 조회

  2. AgentCore Identity에 Custom OAuth2 Provider 등록

  3. OIDC Discovery URL, Token/Auth 엔드포인트 설정

  4. Gateway가 JWT 토큰으로 도구 호출을 인증할 수 있게 됨

검증

CLI 검증

다음 스크립트로 모든 리소스가 정상 생성되었는지 확인합니다:

CLI Verification

콘솔 검증

circle-info

Cognito 도메인 및 AgentCore Identity 검증은 콘솔 접근이 필요합니다. 완전한 검증을 위해 아래 콘솔 검증 단계를 사용하세요.

AWS 콘솔arrow-up-right에서 Amazon Bedrock AgentCore 서비스로 이동합니다. 왼쪽 탭에서 Identity를 선택합니다. **troubleshooting-connectivity-**라는 이름의 identity가 생성되어 있어야 합니다.

선택 사항: AWS 콘솔 기반 검증

AgentCore Identity

코드 분석: Cognito 인증 설정

CloudFormation 기반 자동 배포

scripts/cognito_credentials_provider.py (804줄)는 CloudFormation을 사용하여 Cognito 인프라를 자동으로 배포합니다:

두 가지 인증 흐름

클라이언트
OAuth2 흐름
용도
시크릿

WebUserPoolClient

Authorization Code

사용자 대화형 테스트

없음

MachineUserPoolClient

Client Credentials

Gateway JWT 인증

자동 생성

AgentCore Identity Provider 등록

SSM Parameter Store 구성

모든 인증 정보는 SSM Parameter Store에 저장되어 다른 컴포넌트가 참조합니다:

SSM 파라미터
용도

/app/troubleshooting/agentcore/machine_client_id

M2M 클라이언트 ID

/app/troubleshooting/agentcore/web_client_id

웹 클라이언트 ID

/app/troubleshooting/agentcore/userpool_id

User Pool ID

/app/troubleshooting/agentcore/cognito_provider

프로바이더 식별자

/app/troubleshooting/agentcore/cognito_auth_scope

OAuth2 스코프

/app/troubleshooting/agentcore/cognito_discovery_url

OIDC Discovery URL

/app/troubleshooting/agentcore/cognito_token_url

토큰 엔드포인트

/app/troubleshooting/agentcore/cognito_auth_url

인가 엔드포인트

/app/troubleshooting/agentcore/cognito_domain

Cognito 호스팅 도메인

circle-info

핵심 포인트: Cognito는 두 가지 역할을 수행합니다. (1) 사용자 인증 — 테스트 시 test@example.com으로 로그인, (2) Gateway JWT 인증 — Machine Client가 client_credentials 흐름으로 Bearer Token을 발급받아 Gateway 도구 호출을 인증합니다.

마지막 업데이트