spring-attic / spring-cloud-aws

All development has moved to https://github.com/awspring/spring-cloud-aws Integration for Amazon Web Services APIs with Spring
https://awspring.io/
Apache License 2.0
590 stars 376 forks source link

Provide a way to disable connecting to EC2 when using an S3 compatible server #685

Closed dturanski closed 3 years ago

dturanski commented 3 years ago

I've been able to configure the client to connect to Minio, by setting the endpoint URL. The only remaining issue is I see this exception in the logs:

com.amazonaws.SdkClientException: Failed to connect to service endpoint: 
    at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:100) ~[aws-java-sdk-core-1.11.792.jar:na]
    at com.amazonaws.internal.InstanceMetadataServiceResourceFetcher.getToken(InstanceMetadataServiceResourceFetcher.java:91) ~[aws-java-sdk-core-1.11.792.jar:na]
    at com.amazonaws.internal.InstanceMetadataServiceResourceFetcher.readResource(InstanceMetadataServiceResourceFetcher.java:69) ~[aws-java-sdk-core-1.11.792.jar:na]
    at com.amazonaws.internal.EC2ResourceFetcher.readResource(EC2ResourceFetcher.java:66) ~[aws-java-sdk-core-1.11.792.jar:na]
    at com.amazonaws.util.EC2MetadataUtils.getItems(EC2MetadataUtils.java:402) [aws-java-sdk-core-1.11.792.jar:na]
    at com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:371) [aws-java-sdk-core-1.11.792.jar:na]
    at org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils.isRunningOnCloudEnvironment(AwsCloudEnvironmentCheckUtils.java:38) [spring-cloud-aws-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
    at org.springframework.cloud.aws.context.annotation.OnAwsCloudEnvironmentCondition.matches(OnAwsCloudEnvironmentCondition.java:37) [spring-cloud-aws-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
    at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) [spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:225) [spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599) [spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.access$800(ConfigurationClassParser.java:110) [spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:811) [spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_242]

when trying to determine if the app is running on EC2, I suppose. In addition to the exception, it takes a few seconds for the connection to timeout. It would be nice if there was a way to avoid this.

maciejwalkowiak commented 3 years ago

Thanks @dturanski for reporting. These are known issues - logging comes from AWS SDK and we can't do much about it except muting the logger. The delay comes from autoconfiguring ContextInstanceDataAutoConfiguration - which you can disable if you don't need it. We are aware that it's not convenient that's why we are making all auto-configuration more explicit.

I explained how to handle the issues you have mentioned in the video https://youtu.be/Ts2a-YdN6vI?t=393

dturanski commented 3 years ago

Thanks. I was thinking there may be a way for the user to disable the check with a property if they know they are not running on EC2. I might be able to conditionally disable the autoconfig in my app.