Amazon Athena, a serverless query service in Amazon Simple Storage Service (S3) and a pay-per service, is used to easily analyze data using standard SQL in S3. It has a very high query performance, even for huge datasets and complex queries.
Athena can process both structured and semi-structured data in different file formats such as CSV, JSON, Parquet, and ORC. It can be used to generate reports in connection with BI tools. It uses Hive for creating database and tables. As it has metastore, it can be used with Hadoop, Spark, and Presto.
Sign into AWS console. Then, create your own S3 bucket in S3 to upload data as shown below:
Lastly, create a database and tables in Athena to query the data.
A sample dataset, containing bank transaction data of a customer, is used in this use case. For sample dataset, scroll down to the References section.
- Step: Maps a unit of time in the real world; in this use case, one step represents one hour of time.
- Type: Diverse types of payments (i.e. CASH_IN, CASH_OUT, DEBIT, PAYMENT, and TRANSFER).
- Amount: Amount of transaction in local currency.
- nameOrig: Customer who started the transaction.
- oldbalanceOrg: Initial balance before the transaction.
- newbalanceOrig: New balance after the transaction.
- NameDest: Customer who is the recipient of the transaction.
- OldbalanceDest: Initial balance recipient before the transaction.
- NewbalanceDest: New balance recipient after the transaction.
- IsFraud: Transactions made by the fraudulent agents inside the simulation.
- IsFlaggedFraud: An illegal attempt in this dataset is an attempt to transfer more than 200,000 units in a single transaction.
Note: There is no information for customers name starting with M (Merchants).
Data security plays a significant role in almost all sectors, but especially in financial institutions such as banks, credit unions, and so on. As mobile transactions in the financial industry have increased in recent years, it is highly challenging to secure the data in the mobile platform. In this use case, let's discuss finding and managing malicious behavior during mobile transactions.
In this blog, let's discuss the below use cases:
- Connect Athena with JDBC SQL Workbench Driver.
- Connect Athena with BI Tools (Tableau 10.3).
Connecting Athena With JDBC SQL Workbench Driver
You can query data from AWS console by connecting JDBC SQL workbench with Athena.
- Download Athena jar from this path.
- Ensure the system is configured with Java v1.8.
- Download SQL workbench if needed from this path.
To connect Athena with JDBC driver using SQL workbench, perform the following:
- In SQL workbench, choose File > Manage drivers.
- Perform the configuration shown in the below diagram:
- Add a new driver connection by configuring user name and password as your AWS access key and secret key, respectively.
- Configure your s3_staging_dir in Extended Properties to save your executed queries in your S3 bucket.
Create a table with SQL Workbench.
The table structure is as follows:
The data visualization in table format is as follows:
The data is queried as follows:
Connecting Athena With BI Tools (Tableau 10.3)
To connect Athena with Tableau, perform the following:
- Download Athena connector from this path.
- Place the connector in the C:\Program Files\Tableau\Drivers directory.
- In Tableau, configure the following:
- Server: atena.region.com
- Port: 443
- S3 Staging Directory: s3://yourbucketname/query_save_folder
- Access Key ID
- Secret Access Key
Upon successfully creating connections, Athena databases will be listed out as shown in the below diagram:
A few data visualizations are as follows:
Total amount based on type and IsFraud flag:
New balance and old balance based on type:
Total amount based on type and fraudulent activities:
Minimum new balance and minimum old balance based on type:
Count of steps for fraudulent types of transactions:
Percentage of steps for fraudulent type of activities: