Overview
Lab details
This lab allows users to query and analyse data stored in an S3 bucket using SQL statements. The lab aims to help users understand the process of creating a table in Amazon Athena, configuring the necessary settings, and executing SQL queries. You will practice using Amazon Athena to create a table with a CSV file present in the S3 bucket and query using SQL statements. Duration: 1 hour AWS Region: us-east-1 (N. Virginia).Introduction
What is Amazon Athena?
Amazon Athena is a serverless query service offered by Amazon Web Services (AWS), designed for the analysis of data stored in Amazon S3 using standard SQL queries. The underlying technology of Athena is Presto, an open-source distributed SQL query engine. Supporting various data formats such as CSV, ORC, JSON, Avro, and Apache Parquet, Athena enables users to access it through the AWS Management Console, ODBC/JDBC drivers, or API. Operated on a pay-per-query model, Athena ensures that users are billed only for the executed queries. The service facilitates data analysis through an interactive query editor within the AWS Management Console, allowing users to create tables, define schemas, and execute SQL statements for data exploration and querying. Athena further integrates with other AWS services, such as AWS Glue, for metadata management and data cataloguing. Its notable features include quick query execution and automatic scaling based on the volume and complexity of the data being analysed. This comprehensive functionality makes Amazon Athena a versatile and efficient tool for data analysis within the AWS ecosystem.Architecture diagram

Task details
- Sign in to AWS Management Console.
- Setup workgroup
- Create a database in Glue.
- Query table in Athena
- Validation of the lab
- Deleting AWS Resources
Launching the lab environment
- To launch the lab environment, Click on the Launch lab button.
- Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
- Once the Lab is started, you will be provided with IAM username, Password, Access Key, and Secret Access Key.
You can only start one lab at any given time
Lab guide
Lab steps
Task 1: Sign in to AWS Management Console
- Click on the Open console button, and you will get redirected to AWS Console in a new browser tab.
- On the AWS sign-in page,
- Leave the Account ID as default. Never edit/remove the 12-digit Account ID present in the AWS Console. Otherwise, you cannot proceed with the lab.
- Now copy your Username and Password in the Lab Console to the IAM Username and Password in AWS Console and click on the Sign-in button
- Once Signed In to the AWS Management Console, make the default AWS Region as US East (N. Virginia) us-east-1.
Task 2: Setup workgroup
In this task, we are going to create a workgroup in Amazon Athena. The workgroup allows users to define specific configurations and settings for their query execution environment. By creating a workgroup, users can customize parameters such as query result location, encryption settings, and query execution options.- Make sure you are in the N.Virginia Region.
- Navigate to the Services menu at the top, then click on Athena in the Analytics section.
-
In the left sidebar, under Administration select Workgroup and then click on Create Workgroup button.

-
Provide details to create a workgroup:
- Workgroup Name: Enter WhizWorkgroup
-
Description: Enter Workgroup for Athena lab

-
Analytics engine:
- Choose the type of engine : Select Athena SQL
-
Upgrade Query engine: Select Automatic

-
Under Query result configuration: Select Customer Managed. Then Click on Browse S3 button to select the S3 bucket, whose name is starting with whizlabs… .

- Leave other settings as default
- Click on the Create Workgroup button.
-
Workgroup has been created successfully.

Task 3: Create a database in Glue
In this task, we are going to create a database in AWS Glue, a fully managed extract, transform, and load (ETL) service. The database serves as a container for organizing and storing metadata related to the data tables used in Athena. It enables efficient data cataloging and data management for the subsequent tasks.- Make sure you are in the N.Virginia Region.
- Navigate to the Services menu at the top, then click on AWS Glue in the Analytics section.
- In the left sidebar, Under Data catalog, Click on Databases
-
Click on the Add Database button

-
In the pop-up menu, enter the database name as whizgluedatabase and click on the Create database button.

-
The database is now created.

Task 4: Create a table in Glue
In this task, we are going to create a table in AWS Glue, which represents the structure and schema of the data stored in the S3 bucket.- In the left sidebar, Under the Data catalog, Click on Tables.
-
To create a table, click on the Add table button

-
In the Set table properties section, do the following:
- Enter the Table name : whiz-sample-table
- Database: select whizgluedatabase
-
In the Data store section, do the following:
- Select the type of source: S3 (default)
- Data location is specified in: my account (default)
-
Include path: Select the S3 bucket name starting with whizlabs… . Make sure you add / in the end.

-
In the Choose a data format section, do the following:
- Select Classification as CSV
- Choose delimiter as Comma (,)
-
Click on the Next button.

-
In the Schema section, we will add two columns by clicking on Add button.

- Column # : 1
- Column name: Enter Expense_Type
- Data Type: Select string
-
Click on the Save button below.

- Click on the Add button again.
- Column #: 2
- Column name: Enter Expense_Category
- Data Type: Select string
-
Click on the Save button below.

-
After adding both columns, click on the Next button.

-
Review the configuration of the table and click on the Create button. The table is now created.

Task 5: Query table in Athena
In this task, we are going to use the SQL query capabilities of Amazon Athena to interact with and analyze the data stored in the created table. By executing SQL statements in the Athena Query Editor.- Make sure you are in the N.Virginia Region.
- Navigate to the Services menu in the top, then click on Athena in the Analytics section.
- In the left sidebar, Click on Query Editor
-
Switch to WhizWorkgroup at the top right.

- In the left sidebar, under data source, select the database as whizgluedatabase.
-
Then you will see our table, whiz-sample-table.

-
To preview click on
three dots next to the whiz-sample-table table name and select the Preview Table.

- The query editor will automatically generate the SQL statement for querying the first ten columns.
-
The result of the query is shown below.

-
To get the results of all expenses types under expense_category of Food, paste the following SQL statement into the same query editor or open new query editor by clicking on + symbol and click on Run button.


- You can play around with different queries like the following one.
- To run the new query you can replace the existing one, or you can add a new query by clicking on the + symbol from the query editor.
-
Getting the total number of rows present by running the following SQL statement in the query editor.


Task 6: Validation Test
- Once the lab steps are completed, please click on the Check my work button on the left side panel.
- This will validate the resources in the AWS account and display whether you have completed this lab successfully or not.
-
Sample output :

Task 7: Delete AWS Resources
Deleting the database and table in Glue
- Navigate to the Services menu at the top, then click on AWS Glue in the Analytics section.
- By default, you will be able to see the tables present. In the left sidebar, Under Data catalog, Click on Databases.
- Databases will be present here, our database is whizgluedatabase.
-
To delete the database, perform the following tasks:
- Select the database, whizgluedatabase
- Choose Delete from the menu.
- Confirm the deletion on the pop-up by clicking on the Delete button
- The database is successfully deleted now.
Deleting workgroup
- Navigate to Services menu in the top, then click on Athena in the Analytics section.
- Click on the workgroup.
- Select WhizWorkgroup and Click on Actions
- Click on Delete
- Confirm the deletion on the pop-up by entering workgroup name i.e., WhizWorkgroup and click on the Delete button
Completion and conclusion
- You have successfully created and configured a workgroup in Amazon Athena.
- You have successfully created a table in Amazon Athena with S3
- You have successfully queried the SQL statements in the Query editor of Athena.
- You have successfully created a webpage and published it.
End lab
- Sign out of AWS Account.
- You have successfully completed the lab.
- Once you have completed the steps, click on End lab in the IP Lab Portal.
What gets checked
When you press Check my work, the platform verifies each of these:- Create a Glue Database — Check whether a Glue Database is created or not.
- Create a Glue Table — Check whether an AWS Glue Table exists in any database or not
- Create an Amazon Athena Workgroup — Check whether an Amazon Athena Workgroup is created or not