Using AWS Athena & Document For ALB-ELB Access Logs Analysis
Using AWS Athena & Document For ALB-ELB Access Logs Analysis
Athena Introduction:
Amazon Athena is an interactive query service that makes it easy to analyze data directly in
Amazon Simple Storage Service (Amazon S3) using standard SQL. With a few actions in the AWS
Management Console, you can point Athena at your data stored in Amazon S3 and begin using
standard SQL to run ad-hoc queries and get results in seconds.
Prerequisites
• If you have not already done so, sign up for an account in Setting Up.
• Using the same AWS Region (for example, US West (Oregon)) and account that you are using
for Athena, Create a bucket in Amazon S3 to hold your query results from Athena.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-
overview.html
You can use above url to know how to create S3 Bucket in AWS.
First you will need to create a database that Athena uses to access your data. It's still
a database but data is stored in text files in S3.
1.alb_logs Table
2.elb_logs table
Run the query in the Athena console. After the query completes, Athena registers the
alb_logs table, making the data in it ready for you to issue queries.
2. List all client IP addresses that accessed the Application Load Balancer, and how many
times they accessed the Application Load Balancer.
select distinct client_ip, count() as count from alb_log GROUP by client_ip ORDER by
count() DESC;
3. List the times that a client sent a request to the Application Load Balancer and then
terminated the connection to the Application Load Balancer before the idle timeout elapsed
(HTTP 460 error) for 24 Hours.
select * from "database_name"."alb_logs" where elb_status_code like '4%%' and
time >='2021-03-09T23:55:15' and time <= '2021-03-10T23:55:28';
Kindly You can Search In the below link for more Examples:
https://aws.amazon.com/premiumsupport/knowledge-center/athena-analyze-access-logs/
Where can I find the results of my Amazon Athena queries?
After execute each query in the AWS Athena Console You can see the results at
Result Section in the Athena console or Whatever that Location given in AWS Athena Settings
Meanwhile you can Download the query results files using the Athena console or Download the
query results files from the Amazon Simple Storage Service (Amazon S3) that you specified for the
query location.
Modify the LOCATION Amazon S3 bucket to specify the destination of your Elastic Load
Balancing logs.
Run the query in the Athena console. After the query completes, Athena registers
the elb_logs table, making the data in it ready for queries.
Examples Queries for ELB Logs:
1.This Query will show the number of the same IP requesting your backend with HTTP
response code 200.
Select request_ip, COUNT(*) as count from “elb_logs” WHERE
elb_response_code=200 GROUP BY reques_ip ORDER BY COUNT DESC LIMIT 10;
2. This one will show you which company behind a proxy are using on default browser
“Firefox”
SELECT request_ip, COUNT(*) as client_ip FROM “elb_logs” WHERE user_agent LIKE
'%Firefox%' GROUP BY request_ip ORDER BY client_ip DESC LIMIT 10;
For More Queries Follow the below link.
https://docs.aws.amazon.com/athena/latest/ug/elasticloadbalancer-classic-
logs.html#query-elb-classic-example