Exclude aws dependencies from spring boot autoconfiguration using application.yml and application.properties

Sudha Subramaniam
2 min readJun 11, 2022
Springboot+AWS services

In few scenarios we may to exclude aws dependencies from spring boot autoconfiguration when running project in local env or test cases. If we run the project without excluding then application would fail to start because spring boot autoconfiguration will try to autoconfigure aws dependencies.

Region specific properties cloud.aws.region.auto,cloud.aws.region.static are used to exclude aws dependencies along with spring.autoconfigure.exclude property

If cloud.aws.region.auto=true then based on EC2 meta data Spring boot automatically detect the region , so we need to make it false here

cloud.aws.region.static used to provide region explicitly

And If you are using application.yml then below exclusion configuration would help

specifying profile is most important ,if proper profile is not specified then exclusion will not happen for the expected environment (e.g local)

If you are using application.properties then below exclusion configuration would help

cloud.aws.region.auto=false
cloud.aws.region.static=us-east-1
spring.autoconfigure.exclude[0]=org.springframework.cloud.aws.autoconfigure.cache.ElastiCacheAutoConfiguration
spring.autoconfigure.exclude[1]=org.springframework.cloud.aws.autoconfigure.context.ContextCredentialsAutoConfiguration
spring.autoconfigure.exclude[2]=org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration
spring.autoconfigure.exclude[3]=org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
spring.autoconfigure.exclude[4]=org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
spring.autoconfigure.exclude[5]=org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
spring.autoconfigure.exclude[6]=org.springframework.cloud.aws.autoconfigure.jdbc.AmazonRdsDatabaseAutoConfiguration
spring.autoconfigure.exclude[7]=org.springframework.cloud.aws.autoconfigure.mail.MailSenderAutoConfiguration
spring.autoconfigure.exclude[8]=org.springframework.cloud.aws.autoconfigure.messaging.MessagingAutoConfiguration
spring.autoconfigure.exclude[9]=org.springframework.cloud.aws.autoconfigure.metrics.CloudWatchExportAutoConfiguration

spring.autoconfigure.exclude[10]=org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration

@EnableAutoConfiguration(exclude list) also would help.

--

--