AWS Athena - Getting Started



Setting Up Your AWS Athena Environment

Setting up your AWS Athena environment is simple and important for efficiently running SQL queries on your data stored in Amazon S3.

Prerequisites

Here are the prerequisites before you start using AWS Athena −

  • You must have An AWS account to use AWS Athena.
  • You should have IAM rolesIt allows AWS Athena to access your data from Amazon S3.
  • You should have your data stored in Amazon S3.

Once you fulfil these prerequisites, follow the steps given below to set up your AWS Athena environment −

Step 1: Sign in to AWS Console

First, you need to log in to your AWS Management Console. Then navigate to the Amazon Athena service. You can also search for Athena in the search bar.

Step 2: Create an S3 Bucket

Before running queries, it is mandatory to have your data stored in Amazon S3. It is because AWS Athena queries data directly from S3.

If you have not created a bucket yet, then first create it by going to the S3 service and clicking "Create Bucket" button.

Step 3: Configure AWS Glue Data Catalog

AWS Athena requires a data catalog to define the structure of your datasets. For this, it is recommended to configure AWS Glue Data Catalog.

AWS Glue can automatically integrate with Athena and help you to organize your data into tables. In AWS Glue, you need to create a crawler which scans your S3 data and creates a table schema in the Athena Data Catalog.

Step 4: Set Up IAM Permissions

Aws Athena needs permissions to access S3 and other AWS services. You need to create or assign an IAM role with the necessary permissions for Athena to access your S3 bucket and Glue Data Catalog.

Creating Your First Query in AWS Athena

Now as you set up your AWS Athena environment, you are ready to create your first query in Athena. Creating a query in AWS Athena is a very simple process. It allows you to analyze your data effortlessly.

Follow the steps given below to create your first query in Athena −

Step 1: Open the Athena Console

First, log in to your AWS Management Console and navigate to the Athena service.

Step 2: Select Your Database

Next, open the Athena query editor. Now choose the database where your data is stored. This database should contain your tables.

Check the following image in which we selected database named "tutorialpoint"

Select Your Database

Step 3: Write Your SQL Query

Now, you can start writing your SQL queries. Use the table which you have created and saved in the database you selected.

Step 4: Run the Query

After writing the query, to run it, click on the Run Query button. AWS Athena will execute your SQL statement and retrieve the data from the specified table.

Step 5: View Results

Once your query finishes execution, it will display the result below the query editor. You can also download the results in various formats like CSV.

Step 6: Save Your Query

You can also save your query and use that query again in future.

By following the above steps, you can easily create and run your first query in AWS Athena.

Advertisements