Spring Cloud AWS
Cloudformation
Disable Cloudformation
AWS Configuration
Spring Framework

Disable Cloudformation in Spring Cloud AWS

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Spring Cloud AWS can try to detect CloudFormation stack metadata automatically so it can resolve resource names from the running stack. That is convenient inside AWS, but it is often exactly what you do not want in local development, tests, Docker, or LocalStack environments, where stack auto-detection can cause slow startup, metadata lookups, and credential-related errors.

Why You Might Want It Disabled

CloudFormation integration is useful only if your application actually needs stack-aware resource resolution. If you are running outside AWS or you configure resources explicitly, the extra auto-detection can become a liability.

Typical symptoms include:

  • attempts to contact AWS metadata endpoints during startup
  • credential-chain failures on local machines
  • bean creation errors related to stack detection
  • longer startup time for tests or local development

In those environments, disabling CloudFormation support is usually the correct fix.

The Classic Spring Cloud AWS 2.x Property

In the older Spring Cloud AWS line commonly used with Spring Boot 2.x, the usual switch is:

properties
cloud.aws.stack.auto=false

A YAML version looks like this:

yaml
1cloud:
2  aws:
3    stack:
4      auto: false

This disables automatic CloudFormation stack detection while letting you keep the rest of the AWS integration if you still need it.

Keep It Profile-Specific

The cleanest setup is usually to disable stack auto-detection only in local or test profiles.

yaml
1# application.yml
2cloud:
3  aws:
4    region:
5      static: us-east-1
6
7---
8# application-local.yml
9cloud:
10  aws:
11    stack:
12      auto: false
13    region:
14      static: us-east-1

Then run locally with the appropriate profile:

bash
java -jar app.jar --spring.profiles.active=local

This keeps your AWS-aware configuration available in real cloud environments without forcing local machines to behave like EC2.

Excluding Auto-Configuration Is a Stronger Option

If you want more explicit control, you can exclude the relevant auto-configuration instead of relying only on properties.

java
1import org.springframework.boot.SpringApplication;
2import org.springframework.boot.autoconfigure.SpringBootApplication;
3
4@SpringBootApplication(excludeName = {
5    "org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration"
6})
7public class Application {
8    public static void main(String[] args) {
9        SpringApplication.run(Application.class, args);
10    }
11}

This is heavier than a property toggle, but it is useful when you want the configuration to be unmistakably disabled for a certain application variant.

Because package names and auto-configuration classes can differ between generations of Spring Cloud AWS and awspring, excluding by exact class name should always match the version you actually use.

LocalStack and Explicit Endpoints

Another common pattern is: disable CloudFormation stack detection, but keep explicit AWS clients enabled for LocalStack.

yaml
1cloud:
2  aws:
3    stack:
4      auto: false
5    region:
6      static: us-east-1
java
1import com.amazonaws.client.builder.AwsClientBuilder;
2import com.amazonaws.services.s3.AmazonS3;
3import com.amazonaws.services.s3.AmazonS3ClientBuilder;
4
5public class LocalS3Config {
6    public AmazonS3 localClient() {
7        return AmazonS3ClientBuilder.standard()
8            .withEndpointConfiguration(
9                new AwsClientBuilder.EndpointConfiguration("http://localhost:4566", "us-east-1")
10            )
11            .withPathStyleAccessEnabled(true)
12            .build();
13    }
14}

This keeps local development predictable. The application no longer tries to infer cloud stack details, but it can still talk to emulated AWS services.

Version Drift Requires Attention

Spring Cloud AWS has changed across major versions, including package names and configuration style. That means the exact property or auto-configuration class name may vary depending on whether you are using the older Spring Cloud AWS line or newer awspring modules.

The stable design principle, however, remains the same:

  • disable stack auto-detection when you do not need CloudFormation context
  • configure region and endpoints explicitly in local environments
  • use profiles so cloud-specific behavior is not forced everywhere

That principle is more durable than memorizing one property name out of context.

Common Pitfalls

A common mistake is disabling stack detection but forgetting to set region or endpoints explicitly for local development. The application then fails later for a different AWS auto-configuration reason.

Another issue is copying property names across major Spring Cloud AWS versions without checking which generation of the library the project actually uses.

Developers also sometimes disable CloudFormation globally when they only needed it off in local or test profiles. That can remove useful stack-aware behavior in real AWS deployments.

Finally, excluding auto-configuration by class name is powerful but brittle across version upgrades. Use it carefully and keep it aligned with the actual dependency set.

Summary

  • Disable CloudFormation auto-detection when local or non-AWS environments do not need stack-aware behavior.
  • In classic Spring Cloud AWS 2.x, cloud.aws.stack.auto=false is the common property.
  • Use profiles to keep cloud-specific behavior enabled only where it belongs.
  • Set region and local endpoints explicitly when you disable stack discovery.
  • Watch for version-specific property and package-name changes across Spring Cloud AWS generations.

Course illustration
Course illustration

All Rights Reserved.