Skip to main content

How to get API usage statistics from AWS Athena

  1. Go to Athena Dashboard in AWS
  2. Select Explore Query Editor

    GitHub Action Image

  3. Copy this query into the query editor (change date ranges, example has November 2023):

    SELECT 
    default.alb_logs.request_verb, 
    url_extract_path(default.alb_logs.request_url) as "path",
    default.alb_logs.target_status_code,
    count(*) as "total_calls",
    CAST(min(default.alb_logs.target_processing_time) AS DECIMAL(10, 4)) as "min_duration",
    CAST(max(default.alb_logs.target_processing_time) AS DECIMAL(10, 4)) as "max_duration",
    CAST(avg(default.alb_logs.target_processing_time) AS DECIMAL(10, 4)) as "avg_duration"
    FROM default.alb_logs
    WHERE 
    from_iso8601_timestamp(time) 
    BETWEEN from_iso8601_timestamp('2023-11-01T00:00:00.000Z') AND from_iso8601_timestamp('2023-11-30T23:59:59.999')
    AND default.alb_logs.request_url LIKE 'http%://api.monitor-space-hazards.service.gov.uk%'
    AND user_agent not like 'Pingdom.com%'
    AND url_extract_path(default.alb_logs.request_url) != '/'
    AND default.alb_logs.target_status_code < '400'
    GROUP BY 
    default.alb_logs.request_verb, 
    url_extract_path(default.alb_logs.request_url),
    default.alb_logs.target_status_code
    ORDER BY 
    "total_calls" desc;
    
  4. Select Run query/Run again

    GitHub Action Image

This page was last reviewed on 20 December 2023. It needs to be reviewed again on 20 December 2024 .
This page was set to be reviewed before 20 December 2024. This might mean the content is out of date.