Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Create the table for ALB access logs in Athena using partition projection

Focus mode
Create the table for ALB access logs in Athena using partition projection - Amazon Athena

Because ALB access logs have a known structure whose partition scheme you can specify in advance, you can reduce query runtime and automate partition management by using the Athena partition projection feature. Partition projection automatically adds new partitions as new data is added. This removes the need for you to manually add partitions by using ALTER TABLE ADD PARTITION.

The following example CREATE TABLE statement automatically uses partition projection on ALB access logs from a specified date until the present for a single AWS region. The statement is based on the example in the previous section but adds PARTITIONED BY and TBLPROPERTIES clauses to enable partition projection. In the LOCATION and storage.location.template clauses, replace the placeholders with values that identify the Amazon S3 bucket location of your ALB access logs. For more information about access log file location, see Access log files in the User Guide for Application Load Balancers. For projection.day.range, replace 2022/01/01 with the starting date that you want to use. After you run the query successfully, you can query the table. You do not have to run ALTER TABLE ADD PARTITION to load the partitions. For information about each log file field, see Access log entries.

CREATE EXTERNAL TABLE IF NOT EXISTS alb_access_logs ( type string, time string, elb string, client_ip string, client_port int, target_ip string, target_port int, request_processing_time double, target_processing_time double, response_processing_time double, elb_status_code int, target_status_code string, received_bytes bigint, sent_bytes bigint, request_verb string, request_url string, request_proto string, user_agent string, ssl_cipher string, ssl_protocol string, target_group_arn string, trace_id string, domain_name string, chosen_cert_arn string, matched_rule_priority string, request_creation_time string, actions_executed string, redirect_url string, lambda_error_reason string, target_port_list string, target_status_code_list string, classification string, classification_reason string, conn_trace_id string ) PARTITIONED BY ( day STRING ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' WITH SERDEPROPERTIES ( 'serialization.format' = '1', 'input.regex' = '([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*)[:-]([0-9]*) ([-.0-9]*) ([-.0-9]*) ([-.0-9]*) (|[-0-9]*) (-|[-0-9]*) ([-0-9]*) ([-0-9]*) \"([^ ]*) (.*) (- |[^ ]*)\" \"([^\"]*)\" ([A-Z0-9-_]+) ([A-Za-z0-9.-]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" ([-.0-9]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^ ]*)\" \"([^\\s]+?)\" \"([^\\s]+)\" \"([^ ]*)\" \"([^ ]*)\" ?([^ ]*)?' ) LOCATION 's3://amzn-s3-demo-bucket/AWSLogs/<ACCOUNT-NUMBER>/elasticloadbalancing/<REGION>/' TBLPROPERTIES ( "projection.enabled" = "true", "projection.day.type" = "date", "projection.day.range" = "2022/01/01,NOW", "projection.day.format" = "yyyy/MM/dd", "projection.day.interval" = "1", "projection.day.interval.unit" = "DAYS", "storage.location.template" = "s3://amzn-s3-demo-bucket/AWSLogs/<ACCOUNT-NUMBER>/elasticloadbalancing/<REGION>/${day}" )

For more information about partition projection, see Use partition projection with Amazon Athena.

View related pages

 
Abstracts generated by AI
Athena › ug
Create the table for ALB connection logs in Athena using partition projection

Create ALB connection logs table in Athena using partition projection to reduce query runtime and automate partition management.

August 10, 2024
Athena › ug
Create a table for AWS WAF S3 logs in Athena using partition projection

Athena partition projection automates partition management, reduces query runtime for AWS WAF S3 logs by specifying partition scheme, modifying fields for log output.

April 8, 2025
Athena › ug
Create a table for CloudTrail logs in Athena using manual partitioning

Create table for CloudTrail logs, query in Athena, modify DDL, specify S3 bucket, analyze data across accounts, dates, network activity, partition by region.

October 14, 2024

Discover highly rated pages

 
Abstracts generated by AI
Athena › ug
What is Amazon Athena?

Athena enables SQL queries on Amazon S3 data, Apache Spark applications, and Python development.

March 24, 2025
Athena › ug
Athena engine version 3

Athena engine version 3 introduces performance, reliability enhancements, new features, and query syntax changes for improved data processing and analytics capabilities.

February 3, 2025
Athena › ug
Get started

Athena tutorial covers creating database, table from sample data, querying table, checking results, using named queries, keyboard shortcuts, typeahead suggestions, connecting other data sources.

March 24, 2025
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.