Ready to get started?

Learn more about the CData ODBC Driver for Amazon Athena or download a free trial:

Download Now

MySQL のFederated Table としてAthena Data データを連携利用する

SQL Gateway とODBC Driver を使ってAthena のMySQL Federated Table を構築する。

SQL Gateway を使って、MySQL リモーティングサービスを作成し、Athena のMySQL Federated Table を構築できます。CData ODBC Driver for Athena のMySQL インターフェースのdeamon になります。サービス起動後、MySQL のFEDERATED ストレージエンジンを使ってサーバーおよびテーブルを作成します。Athena data をMySQL テーブルのように使いましょう。

Athena Data への接続

If you have not already done so, provide values for the required connection properties in the data source name (DSN). You can use the built-in Microsoft ODBC Data Source Administrator to configure the DSN. This is also the last step of the driver installation. See the "Getting Started" chapter in the help documentation for a guide to using the Microsoft ODBC Data Source Administrator to create and configure a DSN.

Authenticating to Amazon Athena

To authorize Amazon Athena requests, provide the credentials for an administrator account or for an IAM user with custom permissions: Set AccessKey to the access key Id. Set SecretKey to the secret access key.

Note: Though you can connect as the AWS account administrator, it is recommended to use IAM user credentials to access AWS services.

Obtaining the Access Key

To obtain the credentials for an IAM user, follow the steps below:

  1. Sign into the IAM console.
  2. In the navigation pane, select Users.
  3. To create or manage the access keys for a user, select the user and then select the Security Credentials tab.

To obtain the credentials for your AWS root account, follow the steps below:

  1. Sign into the AWS Management console with the credentials for your root account.
  2. Select your account name or number and select My Security Credentials in the menu that is displayed.
  3. Click Continue to Security Credentials and expand the Access Keys section to manage or create root account access keys.

Authenticating from an EC2 Instance

If you are using the CData Data Provider for Amazon Athena 2018 from an EC2 Instance and have an IAM Role assigned to the instance, you can use the IAM Role to authenticate. To do so, set UseEC2Roles to true and leave AccessKey and SecretKey empty. The CData Data Provider for Amazon Athena 2018 will automatically obtain your IAM Role credentials and authenticate with them.

Authenticating as an AWS Role

In many situations it may be preferable to use an IAM role for authentication instead of the direct security credentials of an AWS root user. An AWS role may be used instead by specifying the RoleARN. This will cause the CData Data Provider for Amazon Athena 2018 to attempt to retrieve credentials for the specified role. If you are connecting to AWS (instead of already being connected such as on an EC2 instance), you must additionally specify the AccessKey and SecretKey of an IAM user to assume the role for. Roles may not be used when specifying the AccessKey and SecretKey of an AWS root user.

Authenticating with MFA

For users and roles that require Multi-factor Authentication, specify the MFASerialNumber and MFAToken connection properties. This will cause the CData Data Provider for Amazon Athena 2018 to submit the MFA credentials in a request to retrieve temporary authentication credentials. Note that the duration of the temporary credentials may be controlled via the TemporaryTokenDuration (default 3600 seconds).

Connecting to Amazon Athena

In addition to the AccessKey and SecretKey properties, specify Database, S3StagingDirectory and Region. Set Region to the region where your Amazon Athena data is hosted. Set S3StagingDirectory to a folder in S3 where you would like to store the results of queries.

If Database is not set in the connection, the data provider connects to the default database set in Amazon Athena.

SQL Gateway の設定

See the SQL Gateway Overview to set up connectivity to Athena data as a virtual MySQL database. You will configure a MySQL remoting service that listens for MySQL requests from clients. The service can be configured in the SQL Gateway UI.

Athena Data のFEDERATED サーバーおよびテーブルを作成

After you have configured and started the service, create a FEDERATED server to simplify the process of creating FEDERATED tables:

FEDERATED サーバーの作成

The following statement will create a FEDERATED server based on the ODBC Driver for Athena. Note that the username and password of the FEDERATED server must match a user account you defined on the Users tab of the SQL Gateway.

CREATE SERVER fedAmazonAthena
FOREIGN DATA WRAPPER mysql
OPTIONS (USER 'sql_gateway_user', PASSWORD 'sql_gateway_passwd', HOST 'sql_gateway_host', PORT ####, DATABASE 'CData AmazonAthena Sys');

FEDERATED テーブルの作成

To create a FEDERATED table using our newly created server, use the CONNECTION keyword and pass the name of the FEDERATED server and the remote table (Customers). Refer to the following template for the statement to create a FEDERATED table:

CREATE TABLE fed_customers (
  ...,
  name  TYPE(LEN),
  totaldue  TYPE(LEN),
  ...,
)
ENGINE=FEDERATED
DEFAULT CHARSET=latin1
CONNECTION='fedAmazonAthena/customers';

NOTE: The table schema for the FEDERATED table must match the remote table schema exactly. You can always connect directly to the MySQL remoting service using any MySQL client and run a SHOW CREATE TABLE query to get the table schema.

クエリの実行

You can now execute queries to the Athena FEDERATED tables from any tool that can connect to MySQL, which is particularly useful if you need to JOIN data from a local table with data from Athena. Refer to the following example:

SELECT 
  fed_customers.name, 
  local_table.custom_field 
FROM 
  local_table 
JOIN 
  fed_customers 
ON 
  local_table.foreign_name = fed_customers.name;
 
 
ダウンロード