Skip to main content

ALB S3 Log View in Athena

Purpose: Create an Athena table for ALB access logs with partition projection so you can query logs efficiently without manually managing partitions. This avoids errors like “No location was specified for table.”

1. Create Athena Table with Partition Projection

Use the following SQL in Athena:
This follows the AWS official recommendation using Partition Projection.

2. Why This Works

  • LOCATION points to the S3 bucket prefix.
  • Regex SerDe parses fields correctly, even when user_agent or request_url contain spaces.
  • Partition Projection automatically manages partitions using the day string (yyyy/MM/dd).
  • No need for manual ALTER TABLE ADD PARTITION or repeated MSCK REPAIR TABLE.
  • Athena computes partition locations using storage.location.template.

3. Optional: Repair Table (if needed)


4. Quick Verification Queries

  1. Test query for a specific day:
  1. Check 4xx/5xx errors in the last 5 hours:

✅ Summary

  • ALB logs from S3 are automatically parsed with correct field mapping.
  • Daily partitions are handled automatically via partition projection.
  • Queries on specific days or error ranges work without manual partition updates.
  • This setup is clean, efficient, and fully compatible with Athena best practices.