DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Understanding RDS Costs
  • Navigate Serverless Databases: A Guide to the Right Solution
  • Seven AWS Data Stores You Can Use To Store and Manage Your Data With Ease
  • Managing Dynamic Application Properties in MuleSoft for CloudHub Applications

Trending

  • Auditing Spring Boot Using JPA, Hibernate, and Spring Data JPA
  • Implementing Stronger RBAC and Multitenancy in Kubernetes Using Istio
  • Hugging Face Is the New GitHub for LLMs
  • Decoding Business Source Licensing: A New Software Licensing Model
  1. DZone
  2. Data Engineering
  3. Databases
  4. Hooking Up MuleSoft and AWS, Part 1: Amazon Athena

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.

Yasir Siraj user avatar by
Yasir Siraj
·
Jul. 10, 17 · Tutorial
Like (3)
Save
Tweet
Share
9.24K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Prerequisites

  • 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:

CREATE EXTERNAL TABLE IF NOT EXISTS sampledb.elb_logs (
  `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'
WITH SERDEPROPERTIES (
  '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.-]*)$'
) LOCATION 'YOUR_S3_URL'
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:beans>
        <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:props>
        <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:props>
        </spring:property>
        </spring:bean>

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

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

jdbc.driver=com.amazonaws.athena.jdbc.AthenaDriver
jdbc.url=jdbc:awsathena://athena.eu-west-1.amazonaws.com:443

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

select elb_name, request_ip,
  request_port,
  backend_ip,
  backend_port,
  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:

http://localhost:8081/athena

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.

AWS Database MuleSoft

Opinions expressed by DZone contributors are their own.

Related

  • Understanding RDS Costs
  • Navigate Serverless Databases: A Guide to the Right Solution
  • Seven AWS Data Stores You Can Use To Store and Manage Your Data With Ease
  • Managing Dynamic Application Properties in MuleSoft for CloudHub Applications

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: