{"record":{"id":"27ed7a5ab4b688bb","repo":"mem0ai/mem0","slug":"aws-bedrock-error-e","errorCode":null,"errorMessage":"AWS Bedrock error: {e}","messagePattern":"AWS Bedrock error: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/llms/aws_bedrock.py","lineNumber":107,"sourceCode":"            self.client = boto3.client(\"bedrock-runtime\", **aws_config)\n\n            # Test connection\n            self._test_connection()\n\n        except NoCredentialsError:\n            raise ValueError(\n                \"AWS credentials not found. Please set AWS_ACCESS_KEY_ID, \"\n                \"AWS_SECRET_ACCESS_KEY, and AWS_REGION environment variables, \"\n                \"or provide them in the config.\"\n            )\n        except ClientError as e:\n            if e.response[\"Error\"][\"Code\"] == \"UnauthorizedOperation\":\n                raise ValueError(\n                    f\"Unauthorized access to Bedrock. Please ensure your AWS credentials \"\n                    f\"have permission to access Bedrock in region {self.config.aws_region}.\"\n                )\n            else:\n                raise ValueError(f\"AWS Bedrock error: {e}\")\n\n    def _test_connection(self):\n        \"\"\"Test connection to AWS Bedrock service.\"\"\"\n        try:\n            # List available models to test connection\n            bedrock_client = boto3.client(\"bedrock\", **self.config.get_aws_config())\n            response = bedrock_client.list_foundation_models()\n            self.available_models = [model[\"modelId\"] for model in response[\"modelSummaries\"]]\n\n            # Check if our model is available\n            if self.config.model not in self.available_models:\n                logger.warning(f\"Model {self.config.model} may not be available in region {self.config.aws_region}\")\n                logger.info(f\"Available models: {', '.join(self.available_models[:5])}...\")\n\n        except Exception as e:\n            logger.warning(f\"Could not verify model availability: {e}\")\n            self.available_models = []\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/llms/aws_bedrock.py#L89-L125","documentation":"Catch-all ValueError raised by _initialize_aws_client for any boto3 ClientError other than UnauthorizedOperation — e.g. AccessDeniedException on list_foundation_models (model access not enabled), ValidationException, ThrottlingException, or region misconfiguration. The underlying AWS error code and message are embedded via {e}, so inspect that text to classify the real cause.","triggerScenarios":"Bedrock model access not enabled for the account (AccessDeniedException on ListFoundationModels); wrong AWS_REGION where Bedrock is unavailable; throttling during init; expired tokens surfacing as ExpiredTokenException","commonSituations":"New AWS account where Bedrock foundation models require console opt-in; unsupported region (e.g. some regions lack Bedrock); STS session tokens expired mid-run; rate limits hit at startup in multi-instance deployments.","solutions":["Read the embedded error code in the message: AccessDeniedException -> enable model access in Bedrock console; ValidationException -> fix config; Throttling -> retry after backoff","Verify AWS_REGION is a Bedrock-supported region and matches the model's availability","Re-authenticate if ExpiredToken: refresh STS session or run aws sso login","Retry initialization with exponential backoff for throttling errors"],"exampleFix":"// before\n# aws_region unset, defaults to unsupported region -> AWS Bedrock error\n\n# after\nMemory.from_config({\"llm\": {\"provider\": \"aws_bedrock\", \"config\": {\n    \"aws_region\": \"us-east-1\", \"model\": \"anthropic.claude-3-5-sonnet-20240620-v1:0\"\n}}})","handlingStrategy":"try-catch","validationCode":"import boto3\nfrom botocore.exceptions import ClientError\n\ntry:\n    boto3.client(\"bedrock\", region_name=region).list_foundation_models()\nexcept ClientError as e:\n    code = e.response[\"Error\"][\"Code\"]\n    raise SystemExit(f\"Bedrock preflight failed: {code}: {e}\")  # classify before mem0 init","typeGuard":null,"tryCatchPattern":"try:\n    llm = AWSBedrockLLM(config)\nexcept ValueError as e:\n    msg = str(e)\n    if \"AccessDeniedException\" in msg:\n        fix = \"enable model access in Bedrock console\"\n    elif \"ThrottlingException\" in msg:\n        fix = \"backoff and retry\"\n    else:\n        fix = \"inspect full AWS error text\"\n    raise RuntimeError(f\"{msg} — suggested fix: {fix}\") from e","preventionTips":["Read the embedded AWS error code before guessing","Use a Bedrock-supported region and enable model access per region","Preflight list_foundation_models once at startup"],"tags":["python","aws","bedrock","api-error","region","mem0"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}