AmazonEc2InstanceDataPropertySource.getProperty() is extremely slow when run outside of Amazon

286 views Asked by At

I am writing a spring boot app which uses Spring Cloud AWS. I noticed a huge slowdown in the loading of the Spring application context as soon as I started including Spring Cloud AWS beans. Previously the context would start in a few seconds however it now takes somewhere in the region of 3 - 5 minutes!

I have traced one of the slowdowns to the getProperty() method in AmazonEc2InstanceDataPropertySource. This tries, several times, to access a link-local IP address (169.254.169.254), which is accessible when running the application within Amazon's network, but is not accessible from outside. It seems that when running outside of Amazon's network the code simply waits for all connection attempts to fail, which I guess is happening when the socket eventually times out?

My first thought was that this timeout might be configurable, or that I might be able to configure a profile to ensure this doesn't happen when running locally but I can't find anything in the docs (http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html) that mentions this at all.

Grateful for any wisdom here, thanks!

2

There are 2 answers

0
kabochkov On

The issue is fixed in spring-cloud-aws 2.3, where it is disabled by default. In case you are still using an older version, there's a workaround - you should explicitly exclude org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration.

For example in application.yml:

spring.autoconfigure.exclude=org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration
0
micjaesc On

See similar problem https://github.com/aws/aws-sdk-java/issues/450

I realized that, for my local environment (Windows 7) , the only way is to define firewall on Link-local address 169.254.169.254 (to fail fast). Haven't found concrete reason why my windows7 behaves differently(so slow) than Mac/win8 with same app.

Anyway, I haven't found any global flag to disable communication with ec2-instance-metadata, when working with local development environment (outside EC2).

cloud.aws.stack.auto=false helps a little, but it was not enough, therefore I've set firewall