Skip to content

Commit 7f0d46e

Browse files
add user documentation for DSQL plugin
1 parent 3b32ac2 commit 7f0d46e

File tree

6 files changed

+180
-19
lines changed

6 files changed

+180
-19
lines changed

README.md

Lines changed: 27 additions & 19 deletions
Large diffs are not rendered by default.

docs/Documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Failover Plugin v2](./using-the-jdbc-driver/using-plugins/UsingTheFailover2Plugin.md)
1515
- [Host Monitoring Plugin](./using-the-jdbc-driver/using-plugins/UsingTheHostMonitoringPlugin.md)
1616
- [IAM Authentication Plugin](./using-the-jdbc-driver/using-plugins/UsingTheIamAuthenticationPlugin.md)
17+
- [Aurora DSQL IAM Authentication Plugin](./using-the-jdbc-driver/using-plugins/UsingTheDsqlAuthenticationPlugin.md)
1718
- [AWS Secrets Manager Plugin](./using-the-jdbc-driver/using-plugins/UsingTheAwsSecretsManagerPlugin.md)
1819
- [Aurora Connection Tracker Plugin](./using-the-jdbc-driver/using-plugins/UsingTheAuroraConnectionTrackerPlugin.md)
1920
- [Driver Metadata Connection Plugin](./using-the-jdbc-driver/using-plugins/UsingTheDriverMetadataConnectionPlugin.md)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# AWS Aurora DSQL IAM Authentication Plugin
2+
3+
## What is IAM?
4+
AWS Identity and Access Management (IAM) grants users access control across all Amazon Web Services. IAM supports granular permissions, giving you the ability to grant different permissions to different users. For more information on IAM and it's use cases, please refer to the [IAM documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html).
5+
6+
## Prerequisites
7+
> [!WARNING]\
8+
> To use this plugin, you must include the runtime dependency [AWS Java SDK DSQL](https://central.sonatype.com/artifact/software.amazon.awssdk/dsql) in your project.
9+
>
10+
> Note: AWS Java SDK DSQL may have transitive dependencies that are also required (ex. [AWS Java SDK Core](https://central.sonatype.com/artifact/software.amazon.awssdk/aws-core/)). If you are not using a package manager such as Maven or Gradle, please refer to Maven Central to determine these transitive dependencies.
11+
12+
To enable the AWS Aurora DSQL IAM Authentication Plugin, add the plugin code `iamDsql` to the [`wrapperPlugins`](../UsingTheJdbcDriver.md#connection-plugin-manager-parameters) value, or to the current [driver profile](../UsingTheJdbcDriver.md#connection-plugin-manager-parameters).
13+
14+
> [!WARNING]\
15+
> The `iam` plugin must NOT be specified when using the `iamDsql` plugin.
16+
17+
This plugin requires valid AWS credentials. See more details at [AWS Credentials Configuration](../custom-configuration/AwsCredentialsConfiguration.md).
18+
19+
## AWS Aurora DQSL IAM Database Authentication
20+
The AWS JDBC Driver supports Amazon AWS Identity and Access Management (IAM) authentication. When using AWS IAM database authentication, the host URL must be a valid Amazon endpoint, and not a custom domain or an IP address.
21+
<br>ie. `cluster-identifier.dsql.us-east-1.on.aws`
22+
23+
Connections established by the `iamDsql` plugin are beholden to the [Cluster quotas and database limits in Amazon Aurora DSQL](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/CHAP_quotas.html). In particular, applications need to consider the maximum transaction duration, and maximum connection duration limits. Ensure connections are returned to the pool regularly, and not retained for long periods.
24+
25+
## How do I use IAM with Aurora DQSL and the AWS JDBC Driver?
26+
1. Configure IAM roles for the cluster according to [Using database roles and IAM authentication](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/using-database-and-iam-roles.html).
27+
2. Add the plugin code `iamDsql` to the [`wrapperPlugins`](../UsingTheJdbcDriver.md#connection-plugin-manager-parameters) parameter value.
28+
29+
| Parameter | Value | Required | Description | Example Value |
30+
|-------------------|:-------:|:--------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
31+
| `iamRegion` | String | Yes | This property will override the default region that is used to generate the IAM token. The default region is parsed from the connection string. | `us-east-2` |
32+
| `iamHost` | String | No | This property will override the default hostname that is used to generate the IAM token. The default hostname is derived from the connection string. | `cluster-identifier.dsql.us-east-1.on.aws` |
33+
| `iamExpiration` | Integer | No | This property determines how long an IAM token is kept in the driver cache before a new one is generated. The default expiration time is set to be 14 minutes and 30 seconds. Note that IAM database authentication tokens have a lifetime of 15 minutes. | `600` |
34+
35+
## Sample code
36+
[AwsAuroraDsqlIamAuthenticationExample.java](../../../examples/AWSDriverExample/src/main/java/software/amazon/AwsAuroraDsqlIamAuthenticationExample.java)<br>
37+
[AwsAuroraDsqlIamAuthenticationDatasourceExample.java](../../../examples/AWSDriverExample/src/main/java/software/amazon/AwsAuroraDsqlIamAuthenticationDatasourceExample.java)

examples/AWSDriverExample/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
implementation("org.postgresql:postgresql:42.7.7")
2020
implementation("com.mysql:mysql-connector-j:9.3.0")
2121
implementation("software.amazon.awssdk:rds:2.31.78")
22+
implementation("software.amazon.awssdk:dsql:2.31.78")
2223
implementation("software.amazon.awssdk:secretsmanager:2.31.12")
2324
implementation("software.amazon.awssdk:sts:2.31.78")
2425
implementation("com.fasterxml.jackson.core:jackson-databind:2.19.0")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package software.amazon;
18+
19+
import com.zaxxer.hikari.HikariDataSource;
20+
import software.amazon.jdbc.ds.AwsWrapperDataSource;
21+
import java.sql.Connection;
22+
import java.sql.ResultSet;
23+
import java.sql.SQLException;
24+
import java.sql.Statement;
25+
import java.util.Properties;
26+
27+
// This file shows how to establish an Aurora DSQL connection using HikariCP datasource and the Aurora DSQL IAM
28+
// authentication plugin.
29+
public class AwsAuroraDsqlIamAuthenticationDatasourceExample {
30+
31+
private static final String IAM_DATABASE_USER = "admin";
32+
33+
public static void main(String[] args) throws SQLException {
34+
try (HikariDataSource ds = new HikariDataSource()) {
35+
36+
// Configure the connection pool:
37+
ds.setUsername(IAM_DATABASE_USER);
38+
39+
// Specify the underlying datasource for HikariCP:
40+
ds.setDataSourceClassName(AwsWrapperDataSource.class.getName());
41+
42+
// Configure AwsWrapperDataSource:
43+
ds.addDataSourceProperty("jdbcProtocol", "jdbc:postgresql://");
44+
ds.addDataSourceProperty("serverName", "cluster-identifier.dsql.us-east-1.on.aws");
45+
ds.addDataSourceProperty("serverPort", "5432");
46+
ds.addDataSourceProperty("database", "postgres");
47+
48+
// Specify the driver-specific data source for AwsWrapperDataSource:
49+
ds.addDataSourceProperty("targetDataSourceClassName", "org.postgresql.ds.PGSimpleDataSource");
50+
51+
Properties targetDataSourceProps = new Properties();
52+
53+
// Enable the Aurora DSQL IAM authentication plugin.
54+
targetDataSourceProps.setProperty("wrapperPlugins", "iamDsql");
55+
56+
ds.addDataSourceProperty("targetDataSourceProperties", targetDataSourceProps);
57+
58+
// Attempt a connection:
59+
try (final Connection conn = ds.getConnection();
60+
final Statement statement = conn.createStatement();
61+
final ResultSet rs = statement.executeQuery("SELECT 1")) {
62+
System.out.println(Util.getResult(rs));
63+
}
64+
}
65+
}
66+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package software.amazon;
18+
19+
import java.sql.Connection;
20+
import java.sql.DriverManager;
21+
import java.sql.ResultSet;
22+
import java.sql.SQLException;
23+
import java.sql.Statement;
24+
import java.util.Properties;
25+
import software.amazon.jdbc.PropertyDefinition;
26+
27+
public class AwsAuroraDsqlIamAuthenticationExample {
28+
public static final String DSQL_CONNECTION_STRING =
29+
"jdbc:aws-wrapper:postgresql://cluster-identifier.dsql.us-east-1.on.aws:5432/postgres";
30+
private static final String USERNAME = "admin";
31+
32+
public static void main(String[] args) throws SQLException {
33+
34+
final Properties properties = new Properties();
35+
36+
// Enable AWS Aurora DSQL IAM database authentication and configure driver property values
37+
properties.setProperty(PropertyDefinition.PLUGINS.name, "iamDsql");
38+
properties.setProperty(PropertyDefinition.USER.name, USERNAME);
39+
40+
// Attempt a connection
41+
try (Connection conn = DriverManager.getConnection(DSQL_CONNECTION_STRING, properties);
42+
Statement statement = conn.createStatement();
43+
ResultSet result = statement.executeQuery("SELECT 1")) {
44+
45+
System.out.println(Util.getResult(result));
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)