Externalized Configuration with Vault and AWS Secrets Manager in Spring Boot

In cloud-native applications, storing sensitive information like API keys, database passwords, and access tokens in application.properties or application.yml is a security risk. To solve this, Spring Boot supports externalized configuration with Vault and AWS Secrets Manager.

This tutorial will walk you through setting up and integrating Vault and AWS Secrets Manager with your Spring Boot application, using com.kscodes.springboot as the base package.

Externalized Configuration with Vault and AWS Secrets Manager in Spring Boot

๐Ÿ” Why Use Vault and AWS Secrets Manager?

Secrets managers help:

  • Avoid hardcoding secrets
  • Rotate credentials automatically
  • Manage access control with IAM policies
  • Provide centralized secret auditing

Both HashiCorp Vault and AWS Secrets Manager are industry-standard tools to store and retrieve secrets securely.

๐Ÿ›  Prerequisites

  • Java 17 or above
  • Spring Boot 3.x
  • Spring Cloud Dependencies
  • AWS Account (for AWS Secrets Manager)
  • Vault installed locally or accessible remotely

๐ŸŒ Step 1: Add Spring Cloud Dependencies

Update your pom.xml:

๐Ÿ— Project Structure

๐Ÿ” Step 2: Setup Spring Cloud Vault

โž• Configuration in bootstrap.yml

โž• Vault Command Example

Now Spring Boot will map:

  • username โ†’ ${username}
  • password โ†’ ${password}

๐Ÿ”‘ Step 3: Setup AWS Secrets Manager Integration

โž• Configuration in bootstrap.yml

In AWS Secrets Manager, create a secret with key:
kscodes/app

Example JSON secret:

๐Ÿ”ง Step 4: Bind Secrets to Java Class

๐Ÿงช Step 5: Use Injected Secrets in Controller

๐Ÿ” Secret Rotation Support

Both Vault and AWS Secrets Manager support:

  • Automatic secret rotation
  • Minimal downtime secret retrieval
  • Spring Cloud reloading via @RefreshScope or actuator /refresh

๐Ÿ“Œ Best Practices for Externalized Configuration with Vault and AWS Secrets Manager

  1. Use bootstrap.yml or application-bootstrap.yml for cloud-specific setup.
  2. Never store credentials in application.yml.
  3. Enable @RefreshScope for dynamic reloads.
  4. Set up IAM roles instead of hardcoding AWS credentials in production.
  5. Limit secret access by app or profile (dev, prod, etc.)

โœ… Summary

  • Vault and AWS Secrets Manager secure sensitive Spring Boot configuration.
  • Spring Cloud makes integration seamless via property binding.
  • You can switch providers without changing your business logic.
  • Externalized configuration improves security, auditability, and maintainability.

Youโ€™ve now implemented externalized configuration with Vault and AWS Secrets Manager in Spring Boot using @ConfigurationProperties.