File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed
examples/SpringBootHikariExample
java/software/amazon/SpringBootHikariExample Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ dependencies {
2323 implementation(" org.springframework.boot:spring-boot-starter-data-jdbc" )
2424 implementation(" org.springframework.boot:spring-boot-starter-web" )
2525 implementation(" org.postgresql:postgresql:42.7.3" )
26+ implementation(" software.amazon.awssdk:sts:2.25.60" )
27+ implementation(" software.amazon.awssdk:rds:2.25.70" )
2628 implementation(project(" :aws-advanced-jdbc-wrapper" ))
2729
2830}
Original file line number Diff line number Diff line change 1818
1919import org .springframework .boot .SpringApplication ;
2020import org .springframework .boot .autoconfigure .SpringBootApplication ;
21+ import software .amazon .awssdk .services .sts .StsClient ;
22+ import software .amazon .awssdk .services .sts .auth .StsAssumeRoleCredentialsProvider ;
23+ import software .amazon .awssdk .services .sts .model .AssumeRoleRequest ;
24+ import software .amazon .jdbc .authentication .AwsCredentialsManager ;
2125
2226@ SpringBootApplication
2327public class SpringBootHikariExampleApplication {
2428 public static void main (String [] args ) {
29+ AwsCredentialsManager .setCustomHandler ((hostSpec , props ) -> {
30+ StsClient stsClient = StsClient .builder ().build ();
31+ AssumeRoleRequest req = AssumeRoleRequest .builder ()
32+ .roleArn ("arn:aws:iam::005965230347:role/iam-poc-testuserb" )
33+ .roleSessionName ("test123" )
34+ .build ();
35+ return StsAssumeRoleCredentialsProvider .builder ()
36+ .stsClient (stsClient )
37+ .refreshRequest (req )
38+ .build ();
39+ });
2540 SpringApplication .run (SpringBootHikariExampleApplication .class , args );
2641 }
2742}
Original file line number Diff line number Diff line change 11spring :
22 datasource :
3- url : jdbc:aws-wrapper:postgresql://db-identifier .cluster-XYZ.us-east -2.rds.amazonaws.com:5432/postgres
4- username : username
5- password : password
3+ url : jdbc:aws-wrapper:postgresql://rds-iam-poc-nonprod .cluster-cjbyytyiqj35.ap-southeast -2.rds.amazonaws.com:5432/postgres
4+ username : testuserb
5+ # password: password
66 driver-class-name : software.amazon.jdbc.Driver
77 hikari :
88 data-source-properties :
9- wrapperPlugins : failover,efm2
9+ wrapperPlugins : failover,efm2,iam
1010 wrapperDialect : aurora-pg
1111 max-lifetime : 840000
1212 minimum-idle : 20
You can’t perform that action at this time.
0 commit comments