Ready to get started?

Download a free trial of the Amazon Athena ODBC Driver to get started:

 Download Now

Learn more:

Amazon Athena Icon Amazon Athena ODBC Driver

The Amazon Athena ODBC Driver is a powerful tool that allows you to connect with live data from Amazon Athena, directly from any applications that support ODBC connectivity.

Access Amazon Athena interactive query services data like you would a database, through a standard ODBC Driver interface.

Build a Simple VCL Application for Amazon Athena Data



How to build a simple VCL Application to view Amazon Athena data in RAD Studio using the CData ODBC Driver for Amazon Athena.

Embarcadero RAD Studio provides a development environment for Delphi and C++Builder applications. With the CData ODBC Driver for Amazon Athena, you gain access to live Amazon Athena data within RAD Studio, abstracting the data into tables, views, and stored procedures that can be used to retrieve and update Amazon Athena data. This article will walk through connecting to Amazon Athena and creating a simple VCL application with the Form Designer.

Create a Connection to Amazon Athena Data

If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.

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.

You can then follow the steps below to use the Data Explorer to create a FireDAC connection to Amazon Athena data.

  1. In a new VCL Forms application, expand the FireDAC node in the Data Explorer.
  2. Right-click the ODBC Data Source node in the Data Explorer.
  3. Click Add New Connection.
  4. Enter a name for the connection.
  5. In the FireDAC Connection Editor that appears, set the DataSource property to the name of the ODBC DSN for Amazon Athena.

Create VCL Applications with Connectivity to Amazon Athena Data

Follow the procedure below to start executing queries to Amazon Athena data from a simple VCL application that displays the results of a query in a grid.

  1. Drop a TFDConnection component onto the form and set the following properties:

    • ConnectionDefName: Select the FireDAC connection to Amazon Athena data.
    • Connected: Select True from the menu and, in the dialog that appears, enter your credentials.
  2. Drop a TFDQuery component onto the form and set the properties below:

    • Connection: Set this property to the TFDConnection component, if this component is not already specified.
    • SQL: Click the button in the SQL property and enter a query. For example:

      SELECT Name, TotalDue FROM Customers
    • Active: Set this property to true.
  3. Drop a TDataSource component onto the form and set the following property:

    • DataSet: In the menu for this property, select the name of the TFDQuery component.
  4. Drop a TDBGrid control onto the form and set the following property:

    • DataSource: Select the name of the TDataSource.
  5. Drop a TFDGUIxWaitCursor onto the form — this is required to avoid a run-time error.

You now have an executable application that displays the results of the SQL Query set in the TFDQuery object.