Ready to get started?

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

 Download Now

Learn more:

Amazon Athena Icon Amazon Athena JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Amazon Athena.

Access Amazon Athena Data in Mule Applications Using the CData JDBC Driver



Create a simple Mule Application that uses HTTP and SQL with the CData JDBC Driver for Amazon Athena to create a JSON endpoint for Amazon Athena data.

The CData JDBC Driver for Amazon Athena connects Amazon Athena data to Mule applications enabling read , write, update, and delete functionality with familiar SQL queries. The JDBC Driver allows users to easily create Mule applications to backup, transform, report, and analyze Amazon Athena data.

This article demonstrates how to use the CData JDBC Driver for Amazon Athena inside of a Mule project to create a Web interface for Amazon Athena data. The application created allows you to request Amazon Athena data using an HTTP request and have the results returned as JSON. The exact same procedure outlined below can be used with any CData JDBC Driver to create a Web interface for the 200+ available data sources.

  1. Create a new Mule Project in Anypoint Studio.
  2. Add an HTTP Connector to the Message Flow.
  3. Configure the address for the HTTP Connector.
  4. Add a Database Select Connector to the same flow, after the HTTP Connector.
  5. Create a new Connection (or edit an existing one) and configure the properties.
    • Set Connection to "Generic Connection"
    • Select the CData JDBC Driver JAR file in the Required Libraries section (e.g. cdata.jdbc.amazonathena.jar).
    • Set the URL to the connection string for Amazon Athena

      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.

      Built-in Connection String Designer

      For assistance in constructing the JDBC URL, use the connection string designer built into the Amazon Athena JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

      java -jar cdata.jdbc.amazonathena.jar

      Fill in the connection properties and copy the connection string to the clipboard.

    • Set the Driver class name to cdata.jdbc.amazonathena.AmazonAthenaDriver.
    • Click Test Connection.
  6. Set the SQL Query Text to a SQL query to request Amazon Athena data. For example: SELECT Name, TotalDue FROM Customers
  7. Add a Transform Message Component to the flow.
  8. Set the Output script to the following to convert the payload to JSON:
    %dw 2.0
    output application/json
    ---
    payload
            
  9. To view your Amazon Athena data, navigate to the address you configured for the HTTP Connector (localhost:8081 by default): http://localhost:8081. The Amazon Athena data is available as JSON in your Web browser and any other tools capable of consuming JSON endpoints.

At this point, you have a simple Web interface for working with Amazon Athena data (as JSON data) in custom apps and a wide variety of BI, reporting, and ETL tools. Download a free, 30 day trial of the JDBC Driver for Amazon Athena and see the CData difference in your Mule Applications today.