Amazon Athena IBM Db2 AS/400 (Db2 iSeries) connector
The Amazon Athena connector for Db2 AS/400 enables Amazon Athena to run SQL queries on your IBM Db2 AS/400 (Db2 iSeries) databases using JDBC.
Prerequisites
Deploy the connector to your AWS account using the Athena console or the AWS Serverless Application Repository. For more information, see Deploy a data source connector or Use the AWS Serverless Application Repository to deploy a data source connector.
Set up a VPC and a security group before you use this connector. For more information, see Create a VPC for a data source connector.
Limitations
-
Write DDL operations are not supported.
-
In a multiplexer setup, the spill bucket and prefix are shared across all database instances.
-
Any relevant Lambda limits. For more information, see Lambda quotas in the AWS Lambda Developer Guide.
-
Date and timestamp data types in filter conditions must be cast to appropriate data types.
Terms
The following terms relate to the Db2 AS/400 connector.
-
Database instance – Any instance of a database deployed on premises, on Amazon EC2, or on Amazon RDS.
-
Handler – A Lambda handler that accesses your database instance. A handler can be for metadata or for data records.
-
Metadata handler – A Lambda handler that retrieves metadata from your database instance.
-
Record handler – A Lambda handler that retrieves data records from your database instance.
-
Composite handler – A Lambda handler that retrieves both metadata and data records from your database instance.
-
Property or parameter – A database property used by handlers to extract database information. You configure these properties as Lambda environment variables.
-
Connection String – A string of text used to establish a connection to a database instance.
-
Catalog – A non-AWS Glue catalog registered with Athena that is a required prefix for the
connection_string
property. -
Multiplexing handler – A Lambda handler that can accept and use multiple database connections.
Parameters
Use the Lambda environment variables in this section to configure the Db2 AS/400 connector.
Connection string
Use a JDBC connection string in the following format to connect to a database instance.
db2as400://${
jdbc_connection_string
}
Using a multiplexing handler
You can use a multiplexer to connect to multiple database instances with a single Lambda function. Requests are routed by catalog name. Use the following classes in Lambda.
Handler | Class |
---|---|
Composite handler | Db2MuxCompositeHandler |
Metadata handler | Db2MuxMetadataHandler |
Record handler | Db2MuxRecordHandler |
Multiplexing handler parameters
Parameter | Description |
---|---|
$ |
Required. A database instance connection string. Prefix the
environment variable with the name of the catalog used in Athena. For example,
if the catalog registered with Athena is
mydb2as400catalog , then the environment
variable name is
mydb2as400catalog_connection_string . |
default |
Required. The default connection string. This string is used
when the catalog is
lambda:${ AWS_LAMBDA_FUNCTION_NAME } . |
The following example properties are for a Db2 MUX Lambda function
that supports two database instances: db2as4001
(the
default), and db2as4002
.
Property | Value |
---|---|
default |
db2as400://jdbc:as400:// |
db2as400_catalog1_connection_string |
db2as400://jdbc:as400://db2as4001. |
db2as400_catalog2_connection_string |
db2as400://jdbc:as400://db2as4002. |
db2as400_catalog3_connection_string |
db2as400://jdbc:as400:// |
Providing credentials
To provide a user name and password for your database in your JDBC connection string, you can use connection string properties or AWS Secrets Manager.
-
Connection String – A user name and password can be specified as properties in the JDBC connection string.
Important
As a security best practice, do not use hardcoded credentials in your environment variables or connection strings. For information about moving your hardcoded secrets to AWS Secrets Manager, see Move hardcoded secrets to AWS Secrets Manager in the AWS Secrets Manager User Guide.
-
AWS Secrets Manager – To use the Athena Federated Query feature with AWS Secrets Manager, the VPC connected to your Lambda function should have internet access
or a VPC endpoint to connect to Secrets Manager. You can put the name of a secret in AWS Secrets Manager in your JDBC connection string. The connector replaces the secret name with the
username
andpassword
values from Secrets Manager.For Amazon RDS database instances, this support is tightly integrated. If you use Amazon RDS, we highly recommend using AWS Secrets Manager and credential rotation. If your database does not use Amazon RDS, store the credentials as JSON in the following format:
{"username": "${username}", "password": "${password}"}
Example connection string with secret name
The following string has the secret name
${secret_name}
.
db2as400://jdbc:as400://
<ip_address>
;<properties>
;:${<secret_name>
};
The connector uses the secret name to retrieve secrets and provide the user name and password, as in the following example.
db2as400://jdbc:as400://
<ip_address>
;user=<username>
;password=<password>
;<properties>
;
Using a single connection handler
You can use the following single connection metadata and record handlers to connect to a single Db2 AS/400 instance.
Handler type | Class |
---|---|
Composite handler | Db2CompositeHandler |
Metadata handler | Db2MetadataHandler |
Record handler | Db2RecordHandler |
Single connection handler parameters
Parameter | Description |
---|---|
default |
Required. The default connection string. |
The single connection handlers support one database instance and must provide a
default
connection string parameter. All other connection
strings are ignored.
The following example property is for a single Db2 AS/400 instance supported by a Lambda function.
Property | Value |
---|---|
default |
db2as400://jdbc:as400:// |
Spill parameters
The Lambda SDK can spill data to Amazon S3. All database instances accessed by the same Lambda function spill to the same location.
Parameter | Description |
---|---|
spill_bucket |
Required. Spill bucket name. |
spill_prefix |
Required. Spill bucket key prefix. |
spill_put_request_headers |
(Optional) A JSON encoded map of request headers and values for
the Amazon S3 putObject request that is used for spilling
(for example, {"x-amz-server-side-encryption" :
"AES256"} ). For other possible headers, see PutObject
in the Amazon Simple Storage Service API Reference. |
Data type support
The following table shows the corresponding data types for JDBC and Apache Arrow.
Db2 AS/400 | Arrow |
---|---|
CHAR | VARCHAR |
VARCHAR | VARCHAR |
DATE | DATEDAY |
TIME | VARCHAR |
TIMESTAMP | DATEMILLI |
DATETIME | DATEMILLI |
BOOLEAN | BOOL |
SMALLINT | SMALLINT |
INTEGER | INT |
BIGINT | BIGINT |
DECIMAL | DECIMAL |
REAL | FLOAT8 |
DOUBLE | FLOAT8 |
DECFLOAT | FLOAT8 |
Partitions and splits
A partition is represented by one or more partition columns of type
varchar
. The Db2 AS/400 connector creates partitions using the following
organization schemes.
-
Distribute by hash
-
Partition by range
-
Organize by dimensions
The connector retrieves partition details such as the number of partitions and column name from one or more Db2 AS/400 metadata tables. Splits are created based upon the number of partitions identified.
Performance
For improved performance, use predicate pushdown to query from Athena, as in the following examples.
SELECT * FROM "lambda:
<LAMBDA_NAME>
"."<SCHEMA_NAME>
"."<TABLE_NAME>
" WHERE integercol = 2147483647
SELECT * FROM "lambda:
<LAMBDA_NAME>
"."<SCHEMA_NAME>
"."<TABLE_NAME>
" WHERE timestampcol >= TIMESTAMP '2018-03-25 07:30:58.878'
Passthrough queries
The Db2 AS/400 connector supports passthrough queries. Passthrough queries use a table function to push your full query down to the data source for execution.
To use passthrough queries with Db2 AS/400, you can use the following syntax:
SELECT * FROM TABLE( system.query( query => '
query string
' ))
The following example query pushes down a query to a data source in Db2 AS/400. The query
selects all columns in the customer
table, limiting the results to 10.
SELECT * FROM TABLE( system.query( query => 'SELECT * FROM customer LIMIT 10' ))
License information
By using this connector, you acknowledge the inclusion of third party components, a list
of which can be found in the pom.xml
Additional resources
For the latest JDBC driver version information, see the pom.xml
For additional information about this connector, visit the corresponding site