@@ -0,0 +1,2726 @@
+//snippet-sourcedescription:%5BCreateDBInstance.java demonstrates how to generate an authorization token for IAM authentication to an Amazon Relational Database Service (RDS)  database.%5D%0A//snippet-keyword:%5BAWS SDK for Java v2%5D%0A//snippet-service:%5BAmazon Relational Database Service%5D%0A%0A/*%0A   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A   SPDX-License-Identifier: Apache-2.0%0A*/%0Apackage com.example.rds;%0A%0A// snippet-start:%5Brds.java2.create_token.import%5D%0Aimport software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;%0Aimport software.amazon.awssdk.regions.Region;%0Aimport software.amazon.awssdk.services.rds.RdsClient;%0Aimport software.amazon.awssdk.services.rds.RdsUtilities;%0Aimport software.amazon.awssdk.services.rds.model.GenerateAuthenticationTokenRequest;%0Aimport software.amazon.awssdk.services.rds.model.RdsException;%0A// snippet-end:%5Brds.java2.create_token.import%5D%0A%0A// snippet-start:%5Brds.java2.create_token.main%5D%0Apublic class GenerateRDSAuthToken %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        final String usage = %22%5Cn%22 +%0A            %22Usage:%5Cn%22 +%0A            %22    %3CdbInstanceIdentifier%3E %3CmasterUsername%3E%5Cn%5Cn%22 +%0A            %22Where:%5Cn%22 +%0A            %22    dbInstanceIdentifier - The database instance identifier. %5Cn%22 +%0A            %22    masterUsername - The master user name. %5Cn%22;%0A%0A            if (args.length != 2) %7B%0A                System.out.println(usage);%0A                System.exit(1);%0A            %7D%0A%0A            String dbInstanceIdentifier = args%5B0%5D;%0A            String masterUsername = args%5B1%5D;%0A            Region region = Region.US_WEST_2;%0A            RdsClient rdsClient = RdsClient.builder()%0A                .region(region)%0A                .credentialsProvider(ProfileCredentialsProvider.create())%0A                .build();%0A%0A            String token = getAuthToken(rdsClient, dbInstanceIdentifier, masterUsername);%0A            System.out.println(%22The token response is %22+token);%0A    %7D%0A%0A    public static String getAuthToken(RdsClient rdsClient, String dbInstanceIdentifier, String masterUsername ) %7B%0A%0A        RdsUtilities utilities = rdsClient.utilities();%0A        try %7B%0A            GenerateAuthenticationTokenRequest tokenRequest = GenerateAuthenticationTokenRequest.builder()%0A                .credentialsProvider(ProfileCredentialsProvider.create())%0A                .username(masterUsername)%0A                .port(3306)%0A                .hostname(dbInstanceIdentifier)%0A                .build();%0A%0A                return utilities.generateAuthenticationToken(tokenRequest);%0A%0A        %7D catch (RdsException e) %7B%0A            System.out.println(e.getLocalizedMessage());%0A            System.exit(1);%0A        %7D%0A        return %22%22;%0A   %7D%0A%7D%0A// snippet-end:%5Brds.java2.create_token.main%5D%0A

Create GenerateRDSAuthToken.java