ResourceNotFoundException
aws_bedrock.ResourceNotFoundException
Stack trace
aws_bedrock.ResourceNotFoundException: The requested model 'model-id' was not found in AWS Bedrock.
at aws_bedrock.client.invoke_model(...) Why it happens
This error occurs because the model identifier provided to the AWS Bedrock client does not match any available models in the AWS Bedrock service. It can happen due to typos, using a model ID that was deleted, or referencing a model from a different AWS region.
Detection
Check the model ID string before making the API call and verify it against the list of available models in your AWS Bedrock console or via the SDK list_models method.
Causes & fixes
Incorrect or misspelled model ID passed to the Bedrock client.
Verify and correct the model ID string to exactly match the model name registered in AWS Bedrock.
Model ID references a model that was deleted or is not deployed in the current AWS region.
Confirm the model is deployed and available in the AWS region configured in your client.
AWS credentials or permissions do not allow access to the specified model.
Ensure your AWS IAM role or user has permissions to access the model resource in Bedrock.
Code: broken vs fixed
import os
from aws_bedrock import BedrockClient
client = BedrockClient(region_name='us-west-2')
response = client.invoke_model(model_id='wrong-model-id', input_text='Hello') # This line triggers ResourceNotFoundException
print(response) import os
from aws_bedrock import BedrockClient
client = BedrockClient(region_name='us-west-2')
# Corrected model_id to existing model
response = client.invoke_model(model_id=os.environ['BEDROCK_MODEL_ID'], input_text='Hello') # Fixed model ID usage
print(response) Workaround
Catch ResourceNotFoundException and fallback to listing available models with client.list_models(), then select a valid model ID dynamically.
Prevention
Implement validation logic to confirm model IDs against the list_models API before invoking models, and use environment variables or configuration management to avoid hardcoding model IDs.