When you build an app that calls Amazon Bedrock, it is common to deploy everything in one AWS region like us-east-1. If that region returns errors or starts throttling requests, users see failures until the issue clears.

A straightforward way to add failover without setting up VPCs or load balancers is to deploy the same Lambda function in two regions (us-east-1 and us-west-2) and put Amazon CloudFront in front of both using an Origin Group.

Here is what we will build and test:

  1. Send a request to CloudFront and confirm it is answered by us-east-1.
  2. Turn on a SIMULATE_OUTAGE=true environment variable in us-east-1 so it returns HTTP 503.
  3. Send the same request again and confirm CloudFront retries us-west-2 and returns HTTP 200.

Source code and IAM policies: github.com/Damdev-95/aws-cloudfront-multi-region-bedrock-failover

How it works

Multi-Region Auto-Failover AI Architecture on AWS

With a CloudFront Origin Group, you configure a primary origin (us-east-1) and a secondary origin (us-west-2), along with the HTTP status codes that should trigger failover (500, 502, 503, 504).

CloudFront sends incoming requests to us-east-1 first. If us-east-1 returns 503, CloudFront retries the request against us-west-2 and returns that response to the caller.

One thing to keep in mind: CloudFront Origin Groups only fail over GET, HEAD, and OPTIONS requests (not POST). For this walkthrough, the Lambda reads the prompt from a ?prompt=... query parameter so failover works directly and you can test it from a browser or with curl.

Prerequisites

  • An AWS account with AWS CLI v2 configured (aws configure)
  • Access to Amazon Nova Micro using the US inference profile (us.amazon.nova-micro-v1:0)

Note on the model ID: While testing this setup, amazon.nova-micro-v1:0 worked in us-east-1, but us-west-2 returned an error asking for an inference profile. Using us.amazon.nova-micro-v1:0 works in both regions.

Step 1: Create the IAM role

Because IAM is global, both Lambda functions can share one role.

Save trust-policy.json:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" }, "Action": "sts:AssumeRole" } ] } 

Save bedrock-policy.json (replace <ACCOUNT_ID> with your 12-digit AWS account ID):

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "bedrock:InvokeModel", "Resource": [ "arn:aws:bedrock:*::foundation-model/amazon.nova-micro-v1:0", "arn:aws:bedrock:*:<ACCOUNT_ID>:inference-profile/us.amazon.nova-micro-v1:0" ] } ] } 

Create the role and attach the policies:

aws iam create-role \ --role-name MultiRegionBedrockRole \ --assume-role-policy-document file://trust-policy.json aws iam attach-role-policy \ --role-name MultiRegionBedrockRole \ --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole aws iam put-role-policy \ --role-name MultiRegionBedrockRole \ --policy-name BedrockNovaMicroInvoke \ --policy-document file://bedrock-policy.json 

Step 2: Write the Lambda function

Save this as app.py. It includes served_by_region in the response so you can see which region handled the request, and checks SIMULATE_OUTAGE so you can test failover.

import json import os import boto3 from botocore.exceptions import ClientError REGION = os.environ["AWS_REGION"] MODEL_ID = "us.amazon.nova-micro-v1:0" bedrock = boto3.client("bedrock-runtime", region_name=REGION) def lambda_handler(event, context): if os.environ.get("SIMULATE_OUTAGE", "false").lower() == "true": return { "statusCode": 503, "headers": {"Content-Type": "application/json"}, "body": json.dumps({"error": f"Simulated outage in {REGION}"}), } params = event.get("queryStringParameters") or {} prompt = params.get("prompt", "What is Amazon CloudFront in one short sentence?") try: response = bedrock.converse( modelId=MODEL_ID, messages=[{"role": "user", "content": [{"text": prompt}]}], inferenceConfig={"maxTokens": 150, "temperature": 0.5}, ) answer = response["output"]["message"]["content"][0]["text"] return { "statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": json.dumps({ "served_by_region": REGION, "model": MODEL_ID, "prompt": prompt, "answer": answer, }), } except ClientError as exc: return { "statusCode": 503, "headers": {"Content-Type": "application/json"}, "body": json.dumps({"error": exc.response["Error"]["Message"]}), } 

Step 3: Deploy the Lambda to both regions

Package app.py and deploy it to us-east-1 and us-west-2 with a Function URL.

Note that public Lambda Function URLs require both lambda:InvokeFunctionUrl and lambda:InvokeFunction (with --invoked-via-function-url), otherwise requests return 403 Forbidden.

ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) ROLE_ARN="arn:aws:iam::${ACCOUNT_ID}:role/MultiRegionBedrockRole" zip app.zip app.py for REGION in us-east-1 us-west-2; do aws lambda create-function \ --function-name bedrock-failover-api \ --runtime python3.12 \ --role "$ROLE_ARN" \ --handler app.lambda_handler \ --zip-file fileb://app.zip \ --timeout 20 \ --region "$REGION" aws lambda add-permission \ --function-name bedrock-failover-api \ --statement-id FunctionURLAllowPublicAccess \ --action lambda:InvokeFunctionUrl \ --principal "*" \ --function-url-auth-type NONE \ --region "$REGION" aws lambda add-permission \ --function-name bedrock-failover-api \ --statement-id FunctionURLInvokeFunctionAllowPublic \ --action lambda:InvokeFunction \ --principal "*" \ --invoked-via-function-url \ --region "$REGION" URL=$(aws lambda create-function-url-config \ --function-name bedrock-failover-api \ --auth-type NONE \ --region "$REGION" \ --query FunctionUrl --output text) echo "$REGION URL: $URL" done 

Note down both hostnames without https:// or the trailing /:

  • us-east-1: abc123.lambda-url.us-east-1.on.aws
  • us-west-2: xyz789.lambda-url.us-west-2.on.aws

Step 4: Configure the CloudFront Origin Group

In the CloudFront Console:

  1. Click Create distribution.
  2. Set Origin domain to your us-east-1 Lambda Function URL hostname, set Protocol to HTTPS only, and name it Bedrock-US-East-1.
  3. Under Default cache behavior:
    • Cache policy: CachingDisabled (so responses are not cached).
    • Origin request policy: AllViewerExceptHostHeader (so ?prompt=... is passed to Lambda).
  4. Click Create distribution.
  5. Open the distribution → Origins tab → Create origin, and add your us-west-2 Lambda hostname as Bedrock-US-West-2 (HTTPS only).
  6. Scroll to Origin groups → Create origin group:
    • Add Bedrock-US-East-1 first, then Bedrock-US-West-2 second.
    • Select 500, 502, 503, and 504 as failover criteria.
    • Name it Bedrock-Failover-Group and save.
  7. Open the Behaviors tab → edit the default (*) behavior → set Origin and origin groups to Bedrock-Failover-Group → save.

Once the distribution status shows Deployed, copy your CloudFront domain name.

Step 5: Test normal traffic and failover

Test 1: Primary region (us-east-1)

curl "https://<your-cloudfront-domain>/?prompt=What+is+Amazon+CloudFront+in+one+short+sentence?" 

Response:

test-result

{ "served_by_region": "us-east-1", "model": "us.amazon.nova-micro-v1:0", "prompt": "What is Amazon CloudFront in one short sentence?", "answer": "Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally." } 

Test 2: Failover to us-west-2

Enable SIMULATE_OUTAGE=true on the us-east-1 Lambda so it returns 503:

aws lambda update-function-configuration \ --function-name bedrock-failover-api \ --environment "Variables={SIMULATE_OUTAGE=true}" \ --region us-east-1 

Wait a few seconds, then run the same curl command:

curl "https://<your-cloudfront-domain>/?prompt=What+is+Amazon+CloudFront+in+one+short+sentence?" 

Response:

{ "served_by_region": "us-west-2", "model": "us.amazon.nova-micro-v1:0", "prompt": "What is Amazon CloudFront in one short sentence?", "answer": "Amazon CloudFront is a fast content delivery network (CDN) that securely delivers data, videos, applications, and APIs to customers worldwide." } 

CloudFront received the 503 from us-east-1, retried us-west-2, and returned a 200 OK response.

Cleanup

  1. Disable and delete the CloudFront distribution.
  2. Delete both Lambda functions and the IAM role:
aws lambda delete-function --function-name bedrock-failover-api --region us-east-1 aws lambda delete-function --function-name bedrock-failover-api --region us-west-2 aws iam delete-role-policy --role-name MultiRegionBedrockRole --policy-name BedrockNovaMicroInvoke aws iam detach-role-policy --role-name MultiRegionBedrockRole --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole aws iam delete-role --role-name MultiRegionBedrockRole 

For production use, you can restrict direct access to the Lambda Function URLs with CloudFront Origin Access Control (OAC) and add AWS WAF rate limiting in front of CloudFront.

How are you handling failover or throttling for your Bedrock apps? Share your approach in the comments.