Amazon Bedrock Cross-Region Inference
๐ Introductionโ
Amazon Bedrock Cross-Region Inference allows you to access foundation models across different AWS regions, providing enhanced flexibility and operational benefits for your AI applications.
Why Cross-Region Inference is Requiredโ
Cross-Region Inference addresses several critical business and technical requirements:
- Model Availability โ Some foundation models may not be available in all AWS regions. Cross-region access ensures you can use the specific models your application requires regardless of your primary region.
- Latency Optimization โ Accessing models in regions closer to your end users reduces response times and improves UX.
- Disaster Recovery โ Provides redundancy and failover options across AWS regions.
- Compliance and Data Residency โ Choose regions that meet your specific regulatory or data residency needs.
- Cost Optimization โ Choose the most cost-effective region based on pricing or capacity.
- Load Distribution โ Distribute workloads to avoid service limits and ensure performance.
๐ Amazon Bedrock User Guide
๐ ๏ธ Step 1: Accessing Cross-Region Inference in Bedrock Consoleโ
โ Prerequisitesโ
- AWS account with necessary permissions
- Knowledge of model regions (e.g., Claude 3 in
us-east-1
, Llama 3 inus-west-2
) - IAM user/role with Bedrock permissions
๐ Setup Guide
๐ Access Bedrock Consoleโ
- Sign in to AWS Console
- Search for Amazon Bedrock and open it
- Switch to the region where your model resides (e.g.,
us-east-1
)
๐ Navigate to Cross-Region Inferenceโ
- In the left menu, click Model access or Cross-region inference (if visible)
- View models and regions in the access matrix
- Enable cross-region access via toggle/button if available
๐ Cross-Region Inference Doc
๐ Step 2: Request Access to Modelsโ
โ Enable Cross-Region Inferenceโ
- Enable the cross-region inference option in the Bedrock console
- Accept the terms and conditions
๐ Select Regions and Modelsโ
- Pick primary and secondary regions
- Select required foundation models (e.g., Claude 3, Titan)
- Click Request Access for each model if not already enabled
๐ Model Access
๐ Monitor Access Statusโ
-
Use the status matrix to check:
- โ Access Granted
- โณ Pending Approval
- โ Denied
๐ Step 3: IAM Setup for Cross-Region Inferenceโ
โ Create IAM User or Roleโ
- Go to IAM Console
- Create a user with Programmatic Access or role for Lambda/SageMaker
๐ Attach Permissionsโ
Use the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:us-east-1:*:model/*",
"arn:aws:bedrock:us-west-2:*:model/*",
"arn:aws:bedrock:eu-central-1:*:model/*",
"arn:aws:bedrock:ap-northeast-1:*:model/*"
]
},
{
"Effect": "Allow",
"Action": [
"bedrock:ListFoundationModels",
"bedrock:GetFoundationModel"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"bedrock:ListCrossRegionInferenceProfiles",
"bedrock:GetCrossRegionInferenceProfile"
],
"Resource": "*"
}
]
}
๐ IAM Policy Guide
๐งช Step 4: Test Cross-Region Inferenceโ
โ Python SDK Exampleโ
import boto3
import json
bedrock = boto3.client(
service_name='bedrock-runtime',
region_name='us-east-1'
)
response = bedrock.invoke_model(
modelId='anthropic.claude-3-sonnet-20240229-v1:0',
body=json.dumps({
"prompt": "Explain AI governance.",
"max_tokens_to_sample": 300
}),
contentType='application/json',
accept='application/json'
)
print(response['body'].read().decode())
โ AWS CLI Exampleโ
aws bedrock-runtime invoke-model \
--region us-east-1 \
--model-id anthropic.claude-3-sonnet-20240229-v1:0 \
--content-type application/json \
--accept application/json \
--body '{"prompt":"Hello Claude","max_tokens_to_sample":300}' \
output.json
๐ธ Step 5: Pricing & Considerationsโ
- Bedrock pricing is per 1,000 tokens for input/output
- No extra charges for using cross-region inference
- Data transfer between regions may incur standard AWS fees
๐ Bedrock Pricing
๐งฐ Step 6: Integration with Unstractโ
To use this model in Unstract:
- Go to Settings > LLMs
- Select New LLM Profile
- Select Amazon Bedrock
- Configure:
- LLM Name: Bedrock
- Region: The region in which model is enabled
- Model Name & Access Keys
- Test and Save