{"record":{"id":"7a2d2c653bab7046","repo":"BoundaryML/baml","slug":"aws-region-is-required-to-build-modular-request-set-it-in","errorCode":null,"errorMessage":"AWS region is required to build modular request. Set it in the client options or via AWS_REGION.","messagePattern":"AWS region is required to build modular request\\. Set it in the client options or via AWS_REGION\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs","lineNumber":440,"sourceCode":"        chat_messages: &[RenderedChatMessage],\n        stream: bool,\n        request_id: HttpRequestId,\n    ) -> Result<HTTPRequest> {\n        if stream {\n            anyhow::bail!(\n                \"AWS Bedrock modular streaming is not supported. Use non-streaming modular requests.\"\n            );\n        }\n\n        let region = self.properties.region.clone().unwrap_or_else(|| {\n            ctx.env_vars()\n                .get(\"AWS_REGION\")\n                .cloned()\n                .unwrap_or_default()\n        });\n\n        if region.is_empty() {\n            anyhow::bail!(\n                \"AWS region is required to build modular request. Set it in the client options or via AWS_REGION.\"\n            );\n        }\n\n        let body_string = serde_json::to_string(&serde_json::Value::Object(\n            self.build_converse_body_json(chat_messages)?,\n        ))?;\n        let body_bytes = body_string.as_bytes().to_vec();\n\n        let host = format!(\"bedrock-runtime.{region}.amazonaws.com\");\n        let encoded_model =\n            utf8_percent_encode(&self.properties.model, PATH_SEGMENT_ENCODE_SET).to_string();\n        let url = format!(\"https://{host}/model/{encoded_model}/converse\");\n\n        let mut header_map = HashMap::new();\n        header_map.insert(\"content-type\".to_string(), \"application/json\".to_string());\n        header_map.insert(\"accept\".to_string(), \"application/json\".to_string());\n","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs#L422-L458","documentation":"The modular Bedrock request path needs an AWS region to construct the request (region is required by the Bedrock Converse endpoint). It reads the region from client options or the AWS_REGION environment variable, and if the resulting value is empty it bails with this error before sending anything.","triggerScenarios":"Calling a function on an aws-bedrock client (modular path) when neither client options specify region nor the AWS_REGION env var is set (or is set to an empty string).","commonSituations":"Deploying to environments (containers, CI, serverless) where AWS_REGION isn't injected; forgetting the region key in client options; AWS_REGION set as empty in .env files.","solutions":["Set region in the client's options block, e.g. options { region us-east-1 }.","Export AWS_REGION (e.g. export AWS_REGION=us-east-1) in the runtime environment.","Ensure the region string isn't empty at deploy time (check .env loading, container env inheritance)."],"exampleFix":"// before\nclient<llm> BedrockNova {\n  provider aws-bedrock\n  options { model nova-pro }\n}\n// after\nclient<llm> BedrockNova {\n  provider aws-bedrock\n  options { model nova-pro region us-east-1 }\n}","handlingStrategy":"validation","validationCode":"region = client_options.get('region') or os.environ.get('AWS_REGION', '')\nif not region:\n    raise ValueError(\"AWS region required: set client options region or AWS_REGION\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the region in the BAML client options instead of relying on the environment","Ensure AWS_REGION is set in all deploy targets (Docker, Lambda, CI)","Validate env vars at app startup with a config check"],"tags":["aws","bedrock","region","config","environment"],"backgroundTag":"missing-env-var","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}