iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⏱️

Find Public IPs Previously Assigned to an ALB Using Athena

に公開
2026/04/05

1. Introduction

You may sometimes want to know the public IP addresses that were previously assigned to an ALB for audit or security investigations.
ALB's public IPs change due to scaling or maintenance, but ALB access logs and connection logs do not include public IP information.
However, I found a relatively simple way to investigate the public IPs previously assigned to an ALB and analyze them with Athena, so I will share that method.

2. ALB Logs

ALB has three types of logs: access logs, connection logs, and health check logs.
For details on what each log contains, please see the following:

The access logs have columns such as "client:port" and "target:port", which refer to the IP address and port of the client that sent the request and the IP address and port of the target (e.g., EC2) that processed the request, respectively.
Similarly, the client_ip in the connection logs is the IP address of the client that sent the request.

Therefore, the logs themselves do not include the public IP of the node that processed the request.

However, the public IP is included in the log file name.
The format of the access log file name is as follows:

bucket[/prefix]/AWSLogs/aws-account-id/elasticloadbalancing/region/yyyy/mm/dd/aws-account-id_elasticloadbalancing_region_app.load-balancer-id_end-time_ip-address_random-string.log.gz

In this format, "ip_address" corresponds to the public IP of the node that processed the request.

https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-log-file-format

3. Athena's $path Metadata Column

Athena provides a metadata column called $path that allows you to retrieve the file name for each row.
The Trino documentation on which Athena is based states the following:

$path: Full file system path name of the file for this row

https://trino.io/docs/current/connector/hive.html#metadata-columns

By using $path, you can query the public IP of the node that processed the ALB request on a per-request basis.

4. Querying Public IPs with Athena

First, enable ALB access logs and create an Athena table for the access logs.

https://docs.aws.amazon.com/ja_jp/athena/latest/ug/create-alb-access-logs-table-partition-projection.html

When resolving the DNS name of the test ALB, two public IPs are currently assigned: 54.249.49.147 and 54.95.54.112.

$ nslookup accesslogTest-alb-468524003.ap-northeast-1.elb.amazonaws.com
# (abbreviated)

Name:    accesslogTest-alb-468524003.ap-northeast-1.elb.amazonaws.com
Addresses:  54.249.49.147
          54.95.54.112

After accessing the ALB several times from a browser, log files were created in S3. The ip-address is one of the resolved IPs: 54.249.49.147.
Created ALB access log file

Also, query the access logs from Athena.
Using "$path", you can retrieve the file name for each row, and by processing it appropriately, you can obtain the public IP.
In the following example, to handle cases where the S3 prefix contains underscores, we split by underscore and take the second-to-last element to get the public IP.

SELECT element_at(split("$path", '_'), -2) public_ip, *
FROM "default"."alb_access_logs"

Query result of ALB access logs from Athena

Also, by querying as shown below, you can find out when the public IP assigned to the ALB changed. In the image below, you can see that on March 20, one of the node's public IPs changed from 57.180.110.16 to 54.249.49.147.

However, since this is based on access logs, it assumes that requests actually reached each node during the relevant period (IPs of nodes that received no access cannot be retrieved).

SELECT DISTINCT day, element_at(split("$path", '_'), -2) public_ip
FROM "default"."alb_access_logs"
ORDER BY day, element_at(split("$path", '_'), -2)

Query result of public IPs assigned to ALB per day from Athena

5. Summary

The public IPs previously assigned to an ALB are not included in the log content, but they are included in the log file names.
Also, by using Athena's $path metadata column, you can investigate the public IPs that were previously assigned to an ALB!

If you ever need to know the public IPs previously assigned to an ALB, I hope this helps.

Discussion