{"record":{"id":"9776b89569269772","repo":"BerriAI/litellm","slug":"aws-region-not-set-set-aws-region-name-or-aws-reg","errorCode":null,"errorMessage":"AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env file","messagePattern":"AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in \\.env file","errorType":"http","errorClass":"BedrockError","httpStatus":401,"severity":"error","filePath":"litellm/llms/bedrock/common_utils.py","lineNumber":446,"sourceCode":"        aws_session_name,\n        aws_profile_name,\n        aws_role_name,\n        aws_web_identity_token,\n    ) = params_to_check\n\n    ssl_verify: Final = _get_bedrock_client_ssl_verify()\n\n    ### SET REGION NAME\n    if region_name:\n        pass\n    elif aws_region_name:\n        region_name = aws_region_name\n    elif litellm_aws_region_name:\n        region_name = litellm_aws_region_name\n    elif standard_aws_region_name:\n        region_name = standard_aws_region_name\n    else:\n        raise BedrockError(\n            message=\"AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env file\",\n            status_code=401,\n        )\n\n    # check for custom AWS_BEDROCK_RUNTIME_ENDPOINT and use it if not passed to init_bedrock_client\n    env_aws_bedrock_runtime_endpoint: Final = get_secret(\"AWS_BEDROCK_RUNTIME_ENDPOINT\")\n    if aws_bedrock_runtime_endpoint:\n        endpoint_url = aws_bedrock_runtime_endpoint\n    elif env_aws_bedrock_runtime_endpoint:\n        endpoint_url = env_aws_bedrock_runtime_endpoint\n    else:\n        endpoint_url = f\"https://bedrock-runtime.{region_name}.amazonaws.com\"\n\n    import boto3\n\n    if isinstance(timeout, float):\n        config = boto3.session.Config(connect_timeout=timeout, read_timeout=timeout)\n    elif isinstance(timeout, httpx.Timeout):","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/common_utils.py#L428-L464","documentation":"Raised during Bedrock client initialization when no AWS region can be resolved: litellm checks the region_name argument, the aws_region_name litellm param, litellm.api_region_name / module-level AWS region name, and the standard AWS_REGION/AWS_DEFAULT_REGION environment variables; if all are empty it raises BedrockError 401 with this fixed message.","triggerScenarios":"Constructing any bedrock/ completion (client init path in common_utils.py) without AWS_REGION_NAME / AWS_REGION / AWS_DEFAULT_REGION set in the environment and without passing aws_region_name to the call or router deployment.","commonSituations":"Fresh containers/CI where AWS credentials are mounted but region env vars are not, deployments that rely only on an AWS profile file (this path reads env vars, not ~/.aws/config), or code that works locally (region set in shell) and fails in production.","solutions":["Set AWS_REGION_NAME or AWS_REGION (e.g. export AWS_REGION=us-east-1) in the runtime environment or .env file.","Or pass the region per call/deployment: litellm.completion(..., aws_region_name=\"us-east-1\") / router model_list entry with aws_region_name.","Add the region to docker-compose / Kubernetes env for the litellm proxy or SDK container.","If relying on an AWS profile, also export AWS_DEFAULT_REGION since profile-only config may not be picked up on this path."],"exampleFix":"# before\nlitellm.completion(model=\"bedrock/anthropic.claude-3-sonnet-20240229-v1:0\", messages=msgs)  # no region anywhere\n\n# after - option 1: env\nimport os; os.environ[\"AWS_REGION_NAME\"] = \"us-east-1\"\n# option 2: per call\nlitellm.completion(model=\"bedrock/anthropic.claude-3-sonnet-20240229-v1:0\", messages=msgs, aws_region_name=\"us-east-1\")","handlingStrategy":"validation","validationCode":"import os\nregion = (\n    os.environ.get(\"AWS_REGION_NAME\")\n    or os.environ.get(\"AWS_REGION\")\n    or os.environ.get(\"AWS_DEFAULT_REGION\")\n)\nif not region:\n    raise RuntimeError(\"Set AWS_REGION_NAME or AWS_REGION before any bedrock/ call\")","typeGuard":"def bedrock_region_configured() -> bool:\n    import os\n    return bool(os.environ.get(\"AWS_REGION_NAME\") or os.environ.get(\"AWS_REGION\") or os.environ.get(\"AWS_DEFAULT_REGION\"))","tryCatchPattern":"from litellm.exceptions import BedrockError\ntry:\n    litellm.completion(model=\"bedrock/<model>\", messages=msgs)\nexcept BedrockError as e:\n    if e.status_code == 401 and \"AWS region not set\" in str(e):\n        raise RuntimeError(\"Deploy config: export AWS_REGION_NAME=us-east-1\") from e\n    raise","preventionTips":["Bake AWS_REGION_NAME into container/CI environment definitions.","Add a startup assertion for region env vars in any service using bedrock models.","Pass aws_region_name explicitly on router deployments so hosts do not depend on shell env."],"tags":["aws","bedrock","configuration","region","environment"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}