spring-cloud-aws
spring-cloud-aws copied to clipboard
Improve failure reporting on missing EC2 metadata
When application runs outside of EC2 instance and region is not specified in application properties, startup fails with IllegalStateException
. This can be done in more developer friendly way using Spring Boot failure analysis which would give developer hint what's the action he has to take in order to solve the problem
@maciejwalkowiak - how we can handle it when running locally?
When running locally I would recommend providing value for static region.
@maciejwalkowiak Can I check this one?
@giova333 would be great!
Finally, I managed to check this issue :)
Since the thrown exception is IllegalStateException
, I think it's a bad practice to analyze such generic exception in FailureAnalyzer
. It'd great to create a dedicated exception RegionNotFoundException
or something like that, and use it in all RegionProvider
implementation when unable to retrieve the region. And for different RegionProvider
implementation we can provide differently action messages:
StaticRegionProvider
-> the region provided in cloud.aws.region.static
is invalid
Ec2MetadataRegionProvider
-> application is running outside ec2 instance, set up the region explicitly using cloud.aws.region.static
DefaultAwsRegionProviderChainDelegate
-> Provide the region either via env variable AWS_REGION_ENV_VAR
, system property aws.region
or ~/.aws/config
file.
The only thing that bothers me is that introducing a new exception is a breaking change, so I am wondering how should we deal with that. @maciejwalkowiak WDYT?
I like this idea. What if we make this new exception type extend IllegalStateException
. In such case it would not be breaking anymore, right?
That was my first thought but unfortunately, different region providers throw different exceptions:
Ec2MetadataRegionProvider
-> IllegalStateException
StaticRegionProvider
-> IllegalArgumentException
DefaultAwsRegionProviderChainDelegate
-> propagates SdkClientException