Ready to get started?

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

 Download Now

Learn more:

Amazon Athena Icon Amazon Athena ADO.NET Provider

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

Publish Crystal Reports on Amazon Athena Data



Use the Report Wizard and standard ADO.NET to design a report based on up-to-date Amazon Athena data.

The CData ADO.NET Provider for Amazon Athena is fully integrated into the SAP Crystal Reports for Visual Studio development environment. You can employ standard ADO.NET components to construct reports, much like you would with SQL Server, but with the added advantage of real-time connectivity to Amazon Athena. This article will guide you through the essential three steps to incorporate Amazon Athena data into a report that refreshes upon opening.

Note: You will need to install SAP Crystal Reports, developer version for Visual Studio to follow this tutorial.

Create a Crystal Reports Application

To follow this article, you will also need a Visual Studio Crystal Reports project. This article will add a report to a WPF application. You can create one by clicking File -> New Project and then selecting the Crystal Reports WPF Application template. In the resulting wizard, select the option to create a blank report.

Connect to Amazon Athena

Creating an ADO.NET data source for Amazon Athena from Server Explorer makes it easy to create a DataSet that can be used in Crystal Reports wizards and the Crystal Reports Designer. You can find a guide to working with Amazon Athena data in Server Explorer in the "Getting Started" chapter of the help documentation.

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.

When you configure the connection, you may also want to set the Max Rows connection property. This will limit the number of rows returned, which is especially helpful for improving performance when designing reports and visualizations.

Create a DataSet

Follow the steps below to use the Visual Studio ADO.NET DataSet Designer to create an ADO.NET DataSet object. Crystal Reports will bind to the DataSet object, which contains Amazon Athena table metadata. Note that this approach also adds a connection string to App.config; you will use this connection string later to load data into the report.

  1. In the Solution Explorer, right-click your project and then click Add -> New Item.
  2. Select DataSet. The DataSet Designer is then displayed.
  3. Drag and drop tables from Server Explorer onto the DataSet Designer. This article uses the Customers table.

Add Amazon Athena Fields to the Report

Follow the steps below to add columns from the DataSet to the report:

  1. Double-click the .rpt file in the Solution Explorer to open the Crystal Reports Designer.
  2. Right-click the designer and click Database -> Database Expert.
  3. Expand the Project Folder and ADO.NET DataSets nodes and drag the DataSet you created into the Selected Tables box. The fields are now accessible from the Field Explorer.
  4. Drag and drop fields from the Field Explorer to the Details section or another section of your report.

Load Data into the Report

Having created the DataSet, which will only contain the metadata, you will now need to create the DataTable containing the actual data. You can use the AmazonAthenaDataAdapter to fill a DataTable with the results of an SQL query.

  1. Add a reference to System.Configuration.dll to your project to be able to use the connection string from App.config.
  2. In App.config, add the following code to the configuration node for compatibility with Crystal Reports when working with .NET 4.0:
    
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
      </startup>
    
  3. Add the following references in your Window.xaml.cs file:

    using System.Configuration;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    using System.Data.CData.AmazonAthena;
    using System.Data;
    
  4. Add the following Window_Loaded method in your Window.xaml.cs to execute the SQL query that will return the DataTable. Note that your query needs to select at least the same columns used in your report.

    private void Window_Loaded(object sender, RoutedEventArgs e) {
      ReportDocument report = new ReportDocument();
      report.Load("../../CrystalReport1.rpt"); 
     var connectionString = ConfigurationManager.ConnectionStrings["MyAppConfigConnectionStringName"].ConnectionString;
      using (AmazonAthenaConnection connection = new AmazonAthenaConnection(connectionString)) {
        AmazonAthenaDataAdapter dataAdapter = new AmazonAthenaDataAdapter(
        "SELECT Name, TotalDue FROM Customers", connection);
         DataSet set = new DataSet("_set");
         DataTable table = set.Tables.Add("_table");
         dataAdapter.Fill(table);
         report.SetDataSource(table);
      }
      reportViewer.ViewerCore.ReportSource = report;
    }
    
  5. In the Window.xaml file, add the Loaded event so that your Window tag resembles the following:

    
    <Window x:Class="CrystalReportWpfApplication4.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:cr="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
            Title="WPF Crystal Report Viewer" Height="600" Width="800" Loaded="Window_Loaded">
            ...
    </Window>
    
  6. Run the report. When the report is loaded, the provider executes the query to retrieve the current data.

Chart Amazon Athena Data

You can also use the DataSet with experts like the Chart Expert:

  1. Right-click in the Crystal Reports Designer and click Insert -> Chart.
  2. Select the Report Header or Report Footer section. The Chart Expert is then displayed.
  3. On the Type tab, select the chart type. This article uses a side-by-side bar chart.
  4. On the Data tab, select the column and conditions for the x-axis. For example, drag the Name column in the DataSet node onto the box under the On Change Of menu.
  5. Select the x-axis column and click the TopN and Order buttons to configure sorting and limiting.
  6. Select the columns and summary operations for the y-axis. For example, drag the TotalDue column in the DataSet node into the Show Values box.
  7. Run the report.

Note that Crystal Reports performs the aggregation on the data already loaded into DataTable, instead of, for example, executing a GROUP BY to the Amazon Athena API. This will also be true for the report creation wizards.

You could gain more control over the queries executed to Amazon Athena by creating another DataSet and populating it with a different query. See the help documentation for more information on the driver's SQL engine.