헤매어도 한 걸음씩

Amazon Bedrock: Cross-Region Inference Profile을 활용한 ValidationException 해결 가이드 본문

ML&DL

Amazon Bedrock: Cross-Region Inference Profile을 활용한 ValidationException 해결 가이드

ritz 2025. 1. 29. 16:53

Amazon Bedrock을 사용하여 Claude 3.5 Sonnet/Haiku를 호출하는 과정에서 ValidationException 오류가 발생했습니다. 단순한 InvokeModel 에러처럼 보이지만, Cross-Region Inference 설정과 관련된 문제였습니다. 이 문제는 Cross-Region을 지원하는 모든 모델에 적용될 수 있으므로, Amazon Bedrock을 활용하는 분들에게 참고가 되길 바랍니다!!

 

문제 해결을 위해선 < 3. 해결 방법 : Inference Profile 을 활용한 API 호출 > 섹션만 확인하시면 됩니다.

 


1. 발생한 오류 

Amazon Bedrock 의 InvokeModel API 를 호출할 때 아래와 같은 ValidationException 에러가 발생할 수 있습니다.

ERROR:__main__:Query error: An error occurred (ValidationException) when calling the InvokeModel operation: Invocation of model ID anthropic.claude-3-5-haiku-20241022-v1:0 with on-demand throughput isn’t supported. Retry your request with the ID or ARN of an inference profile that contains this model.

 

Amazon Bedrock 에선 모델별로 고유한 Inference ID와 API 호출 양식을 요구합니다.
저의 경우, 다음과 같은 이유로 발생하는 ValidationException 에러를 종종 경험했습니다:

 

1. AWS 권한 설정 문제

  • 현재 사용중인 AWS 계정에 Amazon Bedrock 서비스 접근 권한 미설정 
  • 현재 사용중인 리전에서  해당 Bedrock 모델에 대한 사용 권한이 승인되지 않음
  • Amazon Bedrock Model Access 요청 및 승인 절차가 완료되지 않음

2. API 호출 오류

  • 잘못된 Amazon Bedrock Model ID 및 API 호출 양식

 

하지만 이번 케이스에선 동일한 Bedrock Runtime Client로 다른 모델은 정상적으로 호출되는걸 보아 권한 이슈는 아니었고, 또 API 호출 양식도 다시 확인했지만 문제가 없었습니다. 

 

해당 모델에만 발생하는 문제인지 확인하던 중 아래와 같은 글을 발견했습니다.

https://repost.aws/questions/QUEU82wbYVQk2oU4eNwyiong/bedrock-api-invocation-error-on-demand-throughput-isn-s-supported

 

 

정리하자면, Cross-Region Inference 설정과 관련된 문제였습니다. 

아래에선 Cross-Region Inference에 대한 간략한 설명과 함께 문제 해결 방법을 다루고 있습니다.

 

(저는 단순한 InvokeModel 에러로 생각하고 API 호출 방식에만 초점을 맞추었는데요, 에러 메시지를 다시 확인해 보니 해당 모델을 호출하려면 Inference Profile ID 또는 ARN을 사용해야 한다는 중요한 내용을 포함하고 있었습니다... 🥲 )

 

 

 

2. Amazon Bedrock Cross-region Inference Profile  설정

Amazon Bedrock 모델은 각각 다른 API 호출 양식을 가지고 있습니다. 

특히 Cross-region inference를 지원하는 모델들의 경우, 다음과 같은 추가 설정이 필요합니다.

  1. 모델별 Inference Profile (ID 또는 ARN) 생성
  2. 리전별 설정 관리
  3. Inference Profile을 사용하여 모델 호출

Supported cross-region inference profiles 는 아래 공식 문서에서 확인해 볼 수 있습니다.

: https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html#inference-profiles-support-system

 

 

+) Cross-region Inference Profile 이란?

Inference Profile은 Amazon Bedrock에서 특정 모델을 호출할 때 활용되는 리소스로, 다음과 같은 기능을 제공합니다.

  • 사용량 추적: CloudWatch 로그를 설정하여 모델 호출에 대한 메트릭을 수집 및 분석
  • 비용 관리: Inference Profile에 태그를 적용하여 요청 비용을 추적 (AWS 비용 할당 태그 활용)
  • Cross-Region Inference 지원: 여러 리전에 걸쳐 모델 호출 요청을 분산 처리하여 성능 및 속도 향상

Amazon Bedrock에서 제공하는 Inference Profile의 유형은 다음과 같습니다.

  • (시스템 정의) Cross-Region Inference Profile : Amazon Bedrock에서 미리 정의된 프로필로, 여러 리전에 걸쳐 모델 요청을 자동으로 분산처리
  • (사용자 정의) Application Inference Profile : 사용자가 직접 생성하는 프로필로, 단일 리전 또는 여러 리전에 대한 호출 설정

 

 

3. 해결 방법 : Inference Profile 을 활용한 API 호출

1) Inference Profile 생성

AWS 콘솔 또는 CLI에서 Inference Profile을 생성할 수 있습니다.

# AWS CLI를 이용한 Inference Profile 생성
aws bedrock create-inference-profile \
    --profile-name "my-inference-profile" \
    --model-id "anthropic.claude-3-5-haiku-20241022-v1:0"
    
# 생성된 Inference Profile 확인
aws bedrock list-inference-profiles

 

위 명령을 실행하면 생성된 Inference Profile 의 ID와 ARN을 확인할 수 있습니다.

 

2) Inference Profile을 사용하여 모델 호출

이제 InvokeModel API 호출 시 모델 ID 대신 Inference Profile ID 또는 ARN을 사용해야 합니다.

기존 코드 및 수정된 코드 예시는 아래와 같습니다. 

import boto3
bedrock_client = boto3.client("bedrock-runtime")

## 기존 코드 
response = bedrock_client.invoke_model(
	modelId="anthropic.claude-..."
	# 추가 파라미터 
	)

## 수정된 코드 
response = bedrock_client.invoke_model(
	model_id="us.anthropic.claude-3-5-haiku-20241022-v1:0",  # 실제로 사용할 Inference Profile ID 또는 ARN 입력
	# 추가 파라미터
	)

 

 

 

4. 결론 및 참고 자료

Amazon Bedrock에서 Cross-Region Inference를 지원하는 모델을 호출할 때는 반드시 Inference Profile을 생성하여 사용해야 합니다. 일반적인 방식으로 모델을 호출하면 ValidationException 오류가 발생하니 참고하시길 바랍니다!!

 


References