$npx -y skills add giuseppe-trisciuoglio/developer-kit --skill aws-rds-spring-boot-integrationProvides patterns to configure AWS RDS (Aurora, MySQL, PostgreSQL) with Spring Boot applications. Configures HikariCP connection pools, implements read/write splitting, sets up IAM database authentication, enables SSL connections, and integrates with AWS Secrets Manager. Use when
| 1 | # AWS RDS Spring Boot Integration |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Configure AWS RDS databases (Aurora, MySQL, PostgreSQL) with Spring Boot applications. Provides patterns for datasource configuration, HikariCP connection pooling, SSL connections, environment-specific configurations, and AWS Secrets Manager integration. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | Use when configuring HikariCP connection pools for RDS workloads, implementing read/write split with Aurora replicas, setting up IAM database authentication, enabling SSL/TLS connections, managing database migrations with Flyway, or troubleshooting RDS connectivity issues. |
| 10 | |
| 11 | ## Instructions |
| 12 | |
| 13 | Follow these steps to configure AWS RDS with Spring Boot: |
| 14 | |
| 15 | 1. **Add Dependencies** — Include Spring Data JPA, database driver (MySQL/PostgreSQL), and Flyway |
| 16 | 2. **Configure Datasource** — Set connection properties in application.yml |
| 17 | 3. **Configure HikariCP** — Optimize pool settings for your RDS workload |
| 18 | 4. **Set Up SSL** — Enable encrypted connections to RDS |
| 19 | 5. **Configure Profiles** — Set environment-specific configurations (dev/prod) |
| 20 | 6. **Add Migrations** — Create Flyway scripts for schema management |
| 21 | 7. **Validate Connectivity** — Run health check to verify database connection |
| 22 | |
| 23 | **If validation fails**: Check security group rules, verify credentials, ensure RDS is accessible from your network, and confirm SSL certificate configuration. |
| 24 | |
| 25 | 8. **Run Migrations** — Apply Flyway migrations only after connectivity validation passes |
| 26 | |
| 27 | ## Quick Start |
| 28 | |
| 29 | ### Step 1: Add Dependencies |
| 30 | |
| 31 | **Maven (pom.xml):** |
| 32 | ```xml |
| 33 | <dependencies> |
| 34 | <!-- Spring Data JPA --> |
| 35 | <dependency> |
| 36 | <groupId>org.springframework.boot</groupId> |
| 37 | <artifactId>spring-boot-starter-data-jpa</artifactId> |
| 38 | </dependency> |
| 39 | |
| 40 | <!-- Aurora MySQL Driver --> |
| 41 | <dependency> |
| 42 | <groupId>com.mysql</groupId> |
| 43 | <artifactId>mysql-connector-j</artifactId> |
| 44 | <version>8.2.0</version> |
| 45 | <scope>runtime</scope> |
| 46 | </dependency> |
| 47 | |
| 48 | <!-- Aurora PostgreSQL Driver (alternative) --> |
| 49 | <dependency> |
| 50 | <groupId>org.postgresql</groupId> |
| 51 | <artifactId>postgresql</artifactId> |
| 52 | <scope>runtime</scope> |
| 53 | </dependency> |
| 54 | |
| 55 | <!-- Flyway for database migrations --> |
| 56 | <dependency> |
| 57 | <groupId>org.flywaydb</groupId> |
| 58 | <artifactId>flyway-core</artifactId> |
| 59 | </dependency> |
| 60 | |
| 61 | <!-- Validation --> |
| 62 | <dependency> |
| 63 | <groupId>org.springframework.boot</groupId> |
| 64 | <artifactId>spring-boot-starter-validation</artifactId> |
| 65 | </dependency> |
| 66 | </dependencies> |
| 67 | ``` |
| 68 | |
| 69 | **Gradle (build.gradle):** |
| 70 | ```gradle |
| 71 | dependencies { |
| 72 | implementation 'org.springframework.boot:spring-boot-starter-data-jpa' |
| 73 | implementation 'org.springframework.boot:spring-boot-starter-validation' |
| 74 | |
| 75 | // Aurora MySQL |
| 76 | runtimeOnly 'com.mysql:mysql-connector-j:8.2.0' |
| 77 | |
| 78 | // Aurora PostgreSQL (alternative) |
| 79 | runtimeOnly 'org.postgresql:postgresql' |
| 80 | |
| 81 | // Flyway |
| 82 | implementation 'org.flywaydb:flyway-core' |
| 83 | } |
| 84 | ``` |
| 85 | |
| 86 | ### Step 2: Basic Datasource Configuration |
| 87 | |
| 88 | Use the configuration in the **Examples** section below. For PostgreSQL, change: |
| 89 | - Driver: `org.postgresql.Driver` |
| 90 | - URL: `jdbc:postgresql://...` with `?ssl=true&sslmode=require` |
| 91 | - Dialect: `org.hibernate.dialect.PostgreSQLDialect` |
| 92 | |
| 93 | ### Step 3: Set Up Environment Variables |
| 94 | |
| 95 | ```bash |
| 96 | # Production environment variables |
| 97 | export DB_PASSWORD=YourStrongPassword123! |
| 98 | export SPRING_PROFILES_ACTIVE=prod |
| 99 | |
| 100 | # For development |
| 101 | export SPRING_PROFILES_ACTIVE=dev |
| 102 | ``` |
| 103 | |
| 104 | ## Database Migration Setup |
| 105 | |
| 106 | Create migration files for Flyway: |
| 107 | |
| 108 | ``` |
| 109 | src/main/resources/db/migration/ |
| 110 | ├── V1__create_users_table.sql |
| 111 | ├── V2__add_phone_column.sql |
| 112 | └── V3__create_orders_table.sql |
| 113 | ``` |
| 114 | |
| 115 | **V1__create_users_table.sql:** |
| 116 | ```sql |
| 117 | CREATE TABLE users ( |
| 118 | id BIGINT AUTO_INCREMENT PRIMARY KEY, |
| 119 | name VARCHAR(100) NOT NULL, |
| 120 | email VARCHAR(255) NOT NULL UNIQUE, |
| 121 | created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 122 | updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 123 | INDEX idx_email (email) |
| 124 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
| 125 | ``` |
| 126 | |
| 127 | ## Examples |
| 128 | |
| 129 | ### Example 1: Aurora MySQL Configuration |
| 130 | |
| 131 | ```yaml |
| 132 | spring: |
| 133 | datasource: |
| 134 | url: jdbc:mysql://myapp-aurora-cluster.cluster-abc123xyz.us-east-1.rds.amazonaws.com:3306/devops |
| 135 | username: admin |
| 136 | password: ${DB_PASSWORD} |
| 137 | driver-class-name: com.mysql.cj.jdbc.Driver |
| 138 | hikari: |
| 139 | maximum-pool-size: 20 |
| 140 | minimum-idle: 5 |
| 141 | connection-timeout: 20000 |
| 142 | jpa: |
| 143 | hibernate: |
| 144 | ddl-auto: validate |
| 145 | open-in-view: false |
| 146 | ``` |
| 147 | |
| 148 | ### |