{"record":{"id":"55f68cc17202ed62","repo":"spring-projects/spring-ai","slug":"region-is-empty-and-cannot-be-loaded-from-defaulta","errorCode":null,"errorMessage":"Region is empty and cannot be loaded from DefaultAwsRegionProviderChain: ","messagePattern":"Region is empty and cannot be loaded from DefaultAwsRegionProviderChain: ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java","lineNumber":335,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\teventSink.emitError(error, DEFAULT_EMIT_FAILURE_HANDLER);\n\t\t\t\t})\n\t\t\t\t.onEventStream(stream -> stream.subscribe(\n\t\t\t\t\t\t(ResponseStream e) -> e.accept(visitor)))\n\t\t\t\t.build();\n\n\t\tthis.clientStreaming.invokeModelWithResponseStream(invokeRequest, responseHandler);\n\n\t\treturn eventSink.asFlux();\n\t}\n\n\tprivate Region getRegion(Region region) {\n\t\tif (ObjectUtils.isEmpty(region)) {\n\t\t\ttry {\n\t\t\t\treturn DefaultAwsRegionProviderChain.builder().build().getRegion();\n\t\t\t}\n\t\t\tcatch (SdkClientException e) {\n\t\t\t\tthrow new IllegalArgumentException(\"Region is empty and cannot be loaded from DefaultAwsRegionProviderChain: \" + e.getMessage(), e);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn region;\n\t\t}\n\t}\n\n\t/**\n\t * Encapsulates the metrics about the model invocation.\n\t * https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html\n\t *\n\t * @param inputTokenCount The number of tokens in the input prompt.\n\t * @param firstByteLatency The time in milliseconds between the request being sent and the first byte of the\n\t * response being received.\n\t * @param outputTokenCount The number of tokens in the generated text.\n\t * @param invocationLatency The time in milliseconds between the request being sent and the response being received.\n\t */\n\t@JsonInclude(Include.NON_NULL)","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java#L317-L353","documentation":"AbstractBedrockApi requires an AWS region. When the Region parameter is empty/null, it attempts to resolve one through the AWS SDK's DefaultAwsRegionProviderChain (env vars, system properties, profile, EC2/ECS metadata). If that chain also fails with SdkClientException, the constructor throws IllegalArgumentException because a region is mandatory to call Bedrock.","triggerScenarios":"Constructing any AbstractBedrockApi subclass (or the Spring AI auto-configured client) without a Region and without any resolvable default region source (no AWS_REGION/AWS_DEFAULT_REGION env var, no ~/.aws/config profile, no instance metadata).","commonSituations":"Running locally without AWS CLI profile configured; deploying outside AWS without setting the region; passing null Region programmatically; containers missing AWS_REGION env var.","solutions":["Set the AWS_REGION (or AWS_DEFAULT_REGION) environment variable, e.g. export AWS_REGION=us-east-1","Configure the region explicitly in the Spring AI property (e.g. spring.ai.bedrock.aws.region) or pass Region.of(\"us-east-1\") to the constructor","Set up an AWS profile in ~/.aws/config or ensure the runtime environment provides instance metadata"],"exampleFix":"// before\nvar api = new BedrockTitanEmbeddingApi(modelId, null); // no region anywhere\n// after\nvar api = new BedrockTitanEmbeddingApi(modelId, Region.US_EAST_1);","handlingStrategy":"validation","validationCode":"String region = System.getenv(\"AWS_REGION\");\nif (region == null && new File(System.getProperty(\"user.home\") + \"/.aws/config\").exists() == false) {\n    throw new IllegalStateException(\"Set AWS_REGION or spring.ai.bedrock.aws.region before creating the Bedrock client\");\n}","typeGuard":null,"tryCatchPattern":"try { new BedrockTitanEmbeddingApi(modelId, null); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Region is empty\")) { /* prompt for region config */ } throw e; }","preventionTips":["Always set the region explicitly in application properties","Set AWS_REGION in containers/CI environments","Verify DefaultAwsRegionProviderChain sources (env, profile, metadata) exist in the deployment target"],"tags":["aws","bedrock","region","configuration","illegal-argument"],"backgroundTag":"missing-required-config-field","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}