EndpointConnectionError
botocore.exceptions.EndpointConnectionError
Stack trace
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://bedrock-runtime.<region>.amazonaws.com"
Why it happens
This error occurs because the AWS Bedrock runtime service endpoint is not available in the AWS region specified in your boto3 client configuration. Bedrock is only supported in select regions, so attempting to call it in unsupported regions results in this connection failure.
Detection
Catch EndpointConnectionError exceptions when calling Bedrock runtime APIs and log the region used to verify if it is supported before retrying.
Causes & fixes
Using an AWS region where Bedrock runtime service is not yet available.
Change the boto3 client region_name parameter to a supported AWS region such as 'us-east-1' or 'us-west-2' where Bedrock is available.
No explicit region set in boto3 client, defaulting to an unsupported region.
Explicitly specify a supported region in boto3.client('bedrock-runtime', region_name='us-east-1') to ensure the endpoint exists.
Outdated boto3 or botocore version that does not include Bedrock endpoints.
Upgrade boto3 and botocore to the latest versions that include Bedrock service endpoints.
Code: broken vs fixed
import boto3
client = boto3.client('bedrock-runtime') # No region specified, may default to unsupported region
response = client.invoke_model(ModelId='model-id', Body=b'input data') # Raises EndpointConnectionError here import os
import boto3
os.environ['AWS_REGION'] = 'us-east-1' # Set supported region explicitly
client = boto3.client('bedrock-runtime', region_name=os.environ['AWS_REGION']) # Fixed: specify supported region
response = client.invoke_model(ModelId='model-id', Body=b'input data')
print(response) Workaround
Wrap the Bedrock client calls in try/except EndpointConnectionError, and if caught, log the region and fallback to a supported region or notify the user to change region.
Prevention
Always verify Bedrock service availability per region from AWS docs and configure your boto3 clients with supported regions explicitly to avoid endpoint connection failures.