HW3 Guide
DES431 — HW3: Querying Data by Using Athena
Complete Step-by-Step Guide (AWS Academy Data Engineering, Module 4)
Note on scope: This guide covers everything documented in the lecture slides — accessing the lab, the 7-task overview, the fully detailed Task 5 credential setup, and how to submit/end the lab. The click-by-click instructions inside Tasks 1–4, 6, and 7 live in the AWS Academy lab guide itself (the page that opens after you click Start Lab), since the slide deck only summarizes those tasks at a high level. Follow those on-screen instructions when you reach them — this guide tells you exactly where to find them and what each task is trying to accomplish.
Part 1 — What You're Building
Amazon Athena is a serverless, interactive SQL query service that lets you query data sitting directly in Amazon S3 — no database servers to manage.
How the pieces fit together:
Amazon S3 → AWS Glue Crawler → AWS Glue Data Catalog → Amazon Athena → Amazon QuickSight
(raw data) (scans data, infers (stores table/schema (SQL queries (visualization,
schema) metadata) on S3 data) optional)
- S3: stores your raw files (this lab uses a taxi trip dataset in CSV).
- Glue Crawler: scans S3 data and automatically creates table definitions.
- Glue Data Catalog: the "schema registry" — holds database/table metadata.
- Athena: lets you run SQL directly against that cataloged data.
Why it's useful (from the slides):
- Pay only for the data your query actually scans.
- No infrastructure to provision — start querying instantly.
- Standard, open SQL syntax.
- Fast, even on large datasets.
- Supports multiple file formats: CSV, JSON, Parquet, Avro, ORC.
The scenario: A data scientist named Mary needs to run advanced SQL queries across multiple CSV files stored in the same S3 bucket, aggregate them into one queryable database, and clean up the schema (column names/types). You'll set this up for her using Athena + Glue.
Part 2 — Accessing the Lab
Step 1: Go to AWS Academy
- Log in to AWS Academy.
- Select the course: AWS Academy Data Engineering [131274].
Step 2: Navigate to the Right Module
- Click Modules in the left sidebar.
- Open Module 4: Design Principles and Patterns for Data Pipelines.
- Inside the module list, click Lab: Querying Data by Using Athena.
Step 3: Read the Lab Overview
The lab page will show:
"Sofía is happy with the proof of concept (POC) that you created for Amazon S3 and the team is learning how to use it. However, one of the data scientists, Mary, would like to perform more advanced queries on comma-separated values (CSV) data..."
This is your scenario framing — Athena is the tool you'll use to solve Mary's problem. Skim it once before starting.
Part 3 — Starting the Lab
Step 4: Start the Lab Session
- At the top of the lab instructions, click ▶ Start Lab.
- Wait for the environment to provision (you'll see a countdown timer, e.g.
02:11, indicating remaining session time). - Once the green AWS indicator/button appears (top-left area, next to the timer), click it — this opens the AWS Management Console in a new tab.
Step 5: Confirm You're Logged in as the Right User
- In the AWS Console, top-right corner, check the account/user name.
- It must show something starting with
voclabs/...(e.g.voclabs/user2729014=Test_Student). - If you see a different/existing AWS login: sign out of that account first, then reopen the AWS button from the lab page.
⚠️ Logging in with the wrong account is the most common setup mistake — double-check this before doing anything else.
Step 6: Locate Your Cloud Access Credentials (for later use)
Back on the lab instructions page:
- Click
i AWS Details(top bar, next to Start Lab / End Lab). - This expands a Cloud Access panel showing:
- AWS CLI credentials (click
Showto reveal) - Cloud Labs session timing info
- SSH key / AWS SSO details
- Any lab-specific values like
BucketName,MarysAccessKey, etc.
- AWS CLI credentials (click
- You won't need the AWS CLI credentials until Task 5 — but note this panel's location now, since you'll come back to it.
Part 4 — The 7 Tasks (Overview)
According to the slides, this lab has these objectives. Work through them in order, following the detailed instructions that appear inside the AWS Academy lab guide itself for each one:
| # | Task | What You're Doing |
|---|---|---|
| 1 | Create an AWS Glue database from the taxi dataset | Use the Athena query editor to create a Glue database and table; define the schema using Athena's bulk add columns feature |
| 2 | Analyze January taxi data using buckets | The full dataset has all months combined — January has been split into a separate file to optimize your Athena queries |
| 3 | Partition taxi data by paytype | Use partitioning in Athena to organize/optimize queries by payment type |
| 4 | Create Athena views | Build a view that calculates total fare value paid by credit card vs. cash, to simplify analysis for other users |
| 5 | Create Athena named queries via CloudFormation | Use the Cloud9 IDE + CLI + a CloudFormation template to create reusable named queries; review the Policy-For-Data-Scientists IAM policy |
| 6 | Review IAM policy for Athena/Glue access | Examine what permissions Policy-For-Data-Scientists grants for using Athena and Glue |
| 7 | Confirm Mary can use the named query | Verify, using the AWS CLI in Cloud9, that a user (Mary) can successfully access and run the named query |
By the end, you should be able to:
- Use the Athena query editor to create a Glue database and table.
- Define a schema via Athena's bulk add columns feature.
- Configure Athena against an S3 dataset.
- Optimize Athena queries against a sample dataset.
- Create views in Athena.
- Create Athena named queries using CloudFormation.
- Review an IAM policy for Athena named-query users.
- Confirm CLI access to a named query in Cloud9.
Part 5 — Task 5 in Full Detail: Creating Named Queries via CloudFormation
This is the task with fully documented steps in the slides.
Step 7: Understand What This Task Requires
- You'll use the Cloud9 IDE to create a file and run terminal commands.
- Before running any AWS CLI command, you must load temporary session credentials into the terminal — otherwise every
aws ...command will fail with an auth error.
Step 8: Open AWS Details and Expand AWS CLI
- On the lab instructions page, click
i AWS Details. - Find the AWS CLI row and click
Show. - You'll see a credential block like:
[default]
aws_access_key_id=ASIAxxxxxxxxxxxxxxxx
aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
aws_session_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...(very long)- Select and copy the entire block, including the
[default]header line.
⚠️ These are temporary session credentials. They expire when your lab session times out. If a command later fails with an expired/invalid token error, come back to this step, copy a fresh block, and repeat Steps 9–11.
Step 9: Open the Terminal in Cloud9
- Switch to your Cloud9 IDE tab (you may need to open it from the AWS Console — search "Cloud9" — if it's not already open).
- At the bottom of the IDE, find the tab bar:
PROBLEMS | OUTPUT | DEBUG CONSOLE | TERMINAL | PORTS. - Click TERMINAL.
Step 10: Open the Credentials File with nano
In the terminal prompt (it will look like [ec2-user@ip-10-0-1-205 environment]$), type exactly:
nano /home/ec2-user/.aws/credentialsPress Enter.
- This launches the
nanotext editor inside the terminal, showing the contents of the credentials file (it may already contain a default/expired[default]block).
Step 11: Paste Your Credentials
-
Click inside the terminal so it has focus.
-
Paste (
Ctrl+V/Cmd+V) the block you copied in Step 8. -
If old content is present, make sure your final file has one clean
[default]section with all three lines:[default]aws_access_key_id=...aws_secret_access_key=...aws_session_token=...
💡 Never retype the session token by hand — it's very long and easy to mistype. Always copy-paste.
Step 12: Save and Exit nano
nano's shortcuts appear at the bottom of the terminal window (^ = Ctrl):
- Press
Ctrl + Xto begin exiting. nanoasks:Save modified buffer?→ pressY(Yes).- It confirms the filename to save to → press
Enterto confirm and write.
You'll land back at the normal $ terminal prompt.
Step 13: Verify the Credentials Work
Run:
aws sts get-caller-identityExpected success output (your values will differ):
{
"UserId": "AROAR5RZ6L3AR3UR2P6PZ:user5411524=Test_Student",
"Account": "132191772353",
"Arn": "arn:aws:sts::132191772353:assumed-role/voclabs/user5411524=Test_Student"
}- ✅ Success: JSON output showing your name (e.g.
Test_Student) in theArnfield. - ❌ Failure: errors like
Unable to locate credentialsortoken has expired→ re-check Steps 10–12, or grab fresh credentials from Step 8 if your session has timed out.
Step 14: Continue with the Rest of Task 5
Once credentials are verified, continue following the AWS Academy lab guide's on-screen instructions to:
- Create the file needed for the CloudFormation stack.
- Run the AWS CLI command to launch the CloudFormation stack that creates the Athena named query.
- Review the
Policy-For-Data-ScientistsIAM policy referenced in the task.
Part 6 — Submitting Your Work
Step 15: Submit Progress
- At the top of the lab instructions, click Submit.
- When prompted, choose Yes to confirm.
- This records your task-by-task progress and score.
Step 16: Capture Proof for Your Assignment Sheet
- Click your profile/account icon (top-left in the AWS Academy learner interface) to reveal your name.
- Make sure both your name and the score panel (e.g.
Total score 45/45with each task's individual score) are visible on screen. - Take a screenshot showing both, and paste it into your assignment submission sheet.
Example of what the score panel looks like:
Total score 45/45
[Task 1a] Database created 5/5
[Task 1b] Database table created 5/5
[Task 1c] Database table previewed 5/5
[Task 2] Database table jan exists 5/5
[Task 4] Student queried using views 5/5
[Task 5a] Student tested the query 5/5
[Task 5b] CloudFormation stack created 5/5
[Task 5c] CreateNamedQuery event recorded 5/5
[Task 7] GetNamedQuery event recorded 5/5
Each of these line items corresponds to a checkpoint the lab auto-grades as you complete tasks — if any show 0/5, go back and re-check that task before submitting your final screenshot.
Part 7 — Ending the Lab
Step 17: End the Lab Session
- At the top of the lab page, click ■ End Lab.
- Select Yes to confirm you want to end the session.
- This releases your AWS lab environment (credentials from Task 5 will no longer work after this point).
Quick Reference: Full Workflow at a Glance
| Stage | Key Action |
|---|---|
| Access | AWS Academy → Data Engineering [131274] → Module 4 → Lab: Querying Data by Using Athena |
| Start | Click Start Lab → click AWS button → confirm voclabs/... login |
| Tasks 1–4 | Follow on-screen lab guide: create Glue DB/table, analyze Jan data, partition by paytype, create views |
| Task 5 | i AWS Details → Show AWS CLI creds → Cloud9 terminal → nano /home/ec2-user/.aws/credentials → paste → Ctrl+X, Y, Enter → verify with aws sts get-caller-identity → continue CloudFormation steps |
| Tasks 6–7 | Review Policy-For-Data-Scientists IAM policy; confirm named-query access via CLI |
| Submit | Click Submit → Yes → screenshot name + score panel → paste into assignment sheet |
| Finish | Click End Lab → Yes |
Guide compiled from DES431 HW3 lecture slides (Dr. Apichon Witayangkurn, apichon@siit.tu.ac.th).