spring-projects/spring-ai · error · IllegalArgumentException
The region '<region>' is not a valid region!
Error message
The region '<region>' is not a valid region!
What it means
BedrockAwsConnectionConfiguration's StaticRegionProvider converts the configured region string into an AWS SDK Region via Region.of(), which validates it against known AWS regions. If the string is not a recognized region identifier, Region.of throws IllegalArgumentException, which is re-wrapped with this clearer message naming the offending value.
Source
Thrown at auto-configurations/models/spring-ai-autoconfigure-model-bedrock-ai/src/main/java/org/springframework/ai/model/bedrock/autoconfigure/BedrockAwsConnectionConfiguration.java:116
public AwsRegionProvider regionProvider(BedrockAwsConnectionProperties properties) {
if (StringUtils.hasText(properties.getRegion())) {
return new StaticRegionProvider(properties.getRegion());
}
return DefaultAwsRegionProviderChain.builder().build();
}
static class StaticRegionProvider implements AwsRegionProvider {
private final Region region;
StaticRegionProvider(String region) {
try {
this.region = Region.of(region);
}
catch (IllegalArgumentException e) {
throw new IllegalArgumentException("The region '" + region + "' is not a valid region!", e);
}
}
@Override
public Region getRegion() {
return this.region;
}
}
}
View on GitHub (pinned to 98a7beda4f)
Solutions
- Set the region to a valid AWS region code such as us-east-1, us-west-2, eu-central-1, or ap-southeast-1.
- Check for typos, whitespace, or placeholders in the spring.ai.bedrock.aws.region property.
- Omit the property to let the default AWS region provider chain (env var, profile, EC2 metadata) resolve the region instead of a static one.
Example fix
// before spring.ai.bedrock.aws.region=us-east // after spring.ai.bedrock.aws.region=us-east-1
Defensive patterns
Strategy: validation
Validate before calling
String region = properties.getRegion();
Set<String> valid = Region.regions().stream().map(Region::id).collect(Collectors.toSet());
if (region != null && !valid.contains(region)) throw new IllegalArgumentException("Unknown AWS region: " + region); Prevention
- Use exact AWS region codes (us-east-1, eu-west-1, ...).
- Trim whitespace from region config values.
- Prefer the default region provider chain over hardcoding when unsure.
When it happens
Trigger: Setting spring.ai.bedrock.aws.region (or the BedrockAwsConnectionProperties region) to a value AWS SDK v2 does not recognize — misspelled region, wrong casing is fine but wrong format (e.g. 'us-east', 'eu', 'us-east-1a' style) triggers it at bean creation of the region provider.
Common situations: Typos like 'us-east-2 ' with whitespace, invented regions ('us-west-4'), copying a region name from another cloud, or an empty/placeholder value in application.yml.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Region is empty and cannot be loaded from DefaultAwsRegionPr
- Invalid JSON format for the response:
- Filter type not supported:
- NOT operator negation failed for expression type: . Operand:
- Expected Expression but got:
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/fb5a157dc5b4b8e0.
Report an issue: GitHub.