There are more AWS SDK examples available in the AWS Doc SDK Examples
Use Utilities with an AWS SDK
The following code example shows how to use Utilities.
- Java
-
- SDK for Java 2.x
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Returns a RdsUtilities object that generates the authentication token.
public class GenerateRDSAuthToken { public static void main(String[] args) { final String usage = """ Usage: <dbEndpoint> <masterUsername> Where: dbEndpoint - The DB instance endpoint, for example rdsmysql.123456789012.us-west-2.rds.amazonaws.com.\s masterUsername - The master user name.\s """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String dbEndpoint = args[0]; String masterUsername = args[1]; Region region = Region.US_WEST_2; RdsClient rdsClient = RdsClient.builder() .region(region) .build(); String token = getAuthToken(rdsClient, dbEndpoint, masterUsername); System.out.println("The token response is " + token); } public static String getAuthToken(RdsClient rdsClient, String dbEndpoint, String masterUsername) { RdsUtilities utilities = rdsClient.utilities(); try { GenerateAuthenticationTokenRequest tokenRequest = GenerateAuthenticationTokenRequest.builder() .credentialsProvider(ProfileCredentialsProvider.create()) .username(masterUsername) .port(3306) .hostname(dbEndpoint) .build(); return utilities.generateAuthenticationToken(tokenRequest); } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } return ""; } }-
For API details, see Utilities in AWS SDK for Java 2.x API Reference.
-
RebootDBInstance
Scenarios