Spring-cloud-aws: AmazonEc2InstanceDataPropertySource causes slow down on non-EC2 environment

Created on 21 Oct 2015  路  8Comments  路  Source: spring-cloud/spring-cloud-aws

AmazonEc2InstanceDataPropertySource, which is configured by AmazonEc2InstanceDataPropertySourcePostProcessor, causes slow startup since it tries to fetch the ec2 instance metadata automatically.

This is caused by the EC2MetadataUtils.getUserData() call in AmazonEc2InstanceDataPropertySource#getUserData(). It takes more than 7 seconds (EC2MetadataUtils automatically retries three times).

2015-10-21 04:18:58.877 DEBUG 13431 --- [           main] c.amazonaws.internal.EC2MetadataClient   : Connecting to EC2 instance metadata service at URL: http://169.254.169.254/latest/user-data/
2015-10-21 04:19:01.137 DEBUG 13431 --- [           main] c.amazonaws.internal.EC2MetadataClient   : Connecting to EC2 instance metadata service at URL: http://169.254.169.254/latest/user-data/
2015-10-21 04:19:02.387 DEBUG 13431 --- [           main] c.amazonaws.internal.EC2MetadataClient   : Connecting to EC2 instance metadata service at URL: http://169.254.169.254/latest/user-data/
2015-10-21 04:19:05.389  WARN 13431 --- [           main] .e.e.AmazonEc2InstanceDataPropertySource : Error getting instance user-data error message is 'Unable to contact EC2 metadata service.'

I use S3 and spring-cloud-aws on PaaS, not an EC2 instance. I want an option to stop requesting to the EC2 metadata service completely.

Most helpful comment

@tsaqova

I added this exclude to my application class with @SpringBootApplication.

@EnableAutoConfiguration(exclude = { ContextResourceLoaderAutoConfiguration.class, ContextResourceLoaderConfiguration.class, ContextInstanceDataAutoConfiguration.class })

All 8 comments

Fixed with #116

@aemruli

I still see

2016-02-16 13:18:09.412 DEBUG 11217 --- [           main] c.amazonaws.internal.EC2MetadataClient   : Connecting to EC2 instance metadata service at URL: http://169.254.169.254/latest/meta-data/instance-id
2016-02-16 13:18:13.429 DEBUG 11217 --- [           main] com.amazonaws.AmazonWebServiceClient     : Internal logging succesfully configured to commons logger: true

Using version 1.1.0.M2, running on Heroku, need just S3 support

Can we save this 4 seconds also?

+1
How can I disable this check manually? Thanks.

@red0point you can disable it by adding one @EnableAutoConfiguration(exclude = { ContextInstanceDataAutoConfiguration.class })

to your application or one @Configuration file. see this link for more information:
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html
and this issue
https://github.com/spring-cloud/spring-cloud-aws/issues/146

I have subproject A that use

compile("org.springframework.cloud:spring-cloud-starter-aws-messaging:1.1.0.M2")

and subproject B depend on A and use @EnableAutoConfiguration(exclude = { ContextInstanceDataAutoConfiguration.class }) to one of the configuration, and I still see.

12:49:16.020 [restartedMain] DEBUG c.a.internal.EC2MetadataClient - Connecting to EC2 instance metadata service at URL: http://169.254.169.254/latest/meta-data/instance-id
12:49:16.095 [restartedMain] DEBUG s.n.w.p.http.HttpURLConnection - sun.net.www.MessageHeader@65c2fc735 pairs: {GET /latest/meta-data/instance-id HTTP/1.1: null}{User-Agent: Java/1.8.0_77}{Host: 169.254.169.254}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
12:50:22.976 [restartedMain] DEBUG com.amazonaws.AmazonWebServiceClient - Internal logging succesfully configured to commons logger: true

It take 1-2 minutes to get info about metadata service. built using spring boot gradle plugin.
How can I disable this check ? Thanks.

@tsaqova

I added this exclude to my application class with @SpringBootApplication.

@EnableAutoConfiguration(exclude = { ContextResourceLoaderAutoConfiguration.class, ContextResourceLoaderConfiguration.class, ContextInstanceDataAutoConfiguration.class })

@borehack

It works, thanks.

I had a hard time making it work. Thanks @borehack for your answer.

I created a project to gather the settings I found. If it is useful to someone.

https://github.com/robsonbittencourt/springboot-aws-sqs-sleuth-poc

Was this page helpful?
0 / 5 - 0 ratings