spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

Improve failure reporting on missing EC2 metadata

Open maciejwalkowiak opened this issue 6 years ago • 7 comments

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 avatar Jun 11 '18 04:06 maciejwalkowiak

@maciejwalkowiak - how we can handle it when running locally?

balaaagi avatar May 31 '20 16:05 balaaagi

When running locally I would recommend providing value for static region.

maciejwalkowiak avatar May 31 '20 17:05 maciejwalkowiak

@maciejwalkowiak Can I check this one?

giova333 avatar Jun 01 '20 14:06 giova333

@giova333 would be great!

maciejwalkowiak avatar Jun 01 '20 14:06 maciejwalkowiak

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?

giova333 avatar Jun 06 '20 09:06 giova333

I like this idea. What if we make this new exception type extend IllegalStateException. In such case it would not be breaking anymore, right?

maciejwalkowiak avatar Jun 06 '20 19:06 maciejwalkowiak

That was my first thought but unfortunately, different region providers throw different exceptions: Ec2MetadataRegionProvider -> IllegalStateException StaticRegionProvider -> IllegalArgumentException DefaultAwsRegionProviderChainDelegate -> propagates SdkClientException

giova333 avatar Jun 07 '20 05:06 giova333