Over a million developers have joined DZone.

Hooking Up MuleSoft and AWS, Part 1: Amazon Athena

DZone's Guide to

Hooking Up MuleSoft and AWS, Part 1: Amazon Athena

In Part 1 of this AWS/Mule tutorial series, learn how to integrate Amazon Web Services' Amazon Athena with flows in MuleSoft.

· Integration Zone ·
Free Resource

How to Transform Your Business in the Digital Age: Learn how organizations are re-architecting their integration strategy with data-driven app integration for true digital transformation.

Amazon Web Services, a.k.a. AWS, offers a broad set of global cloud-based products including computing, storage, databases, analytics, networking, mobile, developer tools, management tools, IoT, security, and enterprise applications. In this series of articles, "Hooking up MuleSoft and AWS," I will explore some of the services on offer from the AWS platform and see how we can hook these up with MuleSoft. The service I have picked for Part 1 is Amazon Athena.


  • HikariCP - v2.6.1 from here.

  • JDK 1.8.

  • Athena JDBC driver from here.

Amazon Athena

Amazon Athena is an interactive query service that makes it easy to analyze data in Amazon S3 using standard SQL. Athena is serverless, so there is no infrastructure to manage, and you pay only for the queries that you run. It uses Presto with ANSI SQL support and works with a variety of standard data formats, including CSV, JSON, Apache ORC, Avro, and Apache Parquet. Since it uses Amazon S3 as its underlying data store, your data is highly available and durable. You can read more about Amazon Athena here.

Accessing Athena

There are currently two ways to access Athena: using the AWS Management Console or through a JDBC connection. For this article, we will refer to the JDBC option.

Step 1

  • See Getting Started to follow a step-by-step tutorial to create a table and write queries in the Athena Query Editor.
  • Run the Athena onboarding tutorial in the console. You can do this by logging into the AWS Management Console for Athena.

The table I have used has the following structure:

  `request_timestamp` string,
  `elb_name` string,
  `request_ip` string,
  `request_port` int,
  `backend_ip` string,
  `backend_port` int,
  `request_processing_time` double,
  `backend_processing_time` double,
  `client_response_time` double,
  `elb_response_code` string,
  `backend_response_code` string,
  `received_bytes` bigint,
  `sent_bytes` bigint,
  `request_verb` string,
  `url` string,
  `protocol` string,
  `user_agent` string,
  `ssl_cipher` string,
  `ssl_protocol` string 
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
  'serialization.format' = '1',
  'input.regex' = ' ([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*):([0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) (-|[0-9]*) (-|[0-9]*) ([-0-9]*) ([-0-9]*) \\\"([^ ]*) ([^ ]*) (- |[^ ]*)\\\" (\"[^\"]*\") ([A-Z0-9-]+) ([A-Za-z0-9.-]*)$'
TBLPROPERTIES ('has_encrypted_data'='false');

Before moving on to the next step, you'll also need to add the following policies to the user profile, which you'll use to connect to the database you've created:

Image title

Step 2

Create a new Mule Project. Add Athena JDBC driver and HikariCP jars in the build path.

Image title

Next, add an HTTP listener.

Image title

For the HTTP listener configuration, I have used port 8081.

Image title

We will be using a generic database configuration. In our case, we will be using a datasource reference. Let's define the datasource reference bean in the configuration of the XML source.

    <context:property-placeholder location="app.properties"/> 
        <spring:bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
            <spring:property name="jdbcUrl" value="${jdbc.url}"/>
            <spring:property name="driverClassName" value="${jdbc.driver}"/>
        <spring:property name="dataSourceProperties">
        <spring:prop key="s3_staging_dir">s3://S3 Bucket Location/</spring:prop>
        <spring:prop key="log_level">INFO</spring:prop>     
        <spring:prop key="user">AWSAccessKey</spring:prop>
        <spring:prop key="password">AWSSecretAccessKey</spring:prop>   

    <spring:bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">  
          <spring:constructor-arg ref="hikariConfig" />  

We have added a global property placeholder in app.properties.


Next, we will write down our SQL query to retrieve data from our newly created database table.

select elb_name, request_ip,
  request_processing_time from sampledb.elb_logs limit 5;

Image title

As the last step, let's add an Object to JSON transformer to our flow. Once added, we are all set to test our newly developed Mule flow. Let's run the project and open a new browser. Hit the following URL:


You should see a similar response as below in your browser window:

Image title

All done. I hope this article helps you understand how to hook up MuleSoft with Amazon Athena.

Build and deploy API integrations 7x faster. Try the Cloud Elements 100% RESTful platform for 30 days free. Access your trial here.

mulesoft ,aws ,sql ,athena ,integration ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}