Search code examples
amazon-web-servicesaws-api-gatewaymonitoringamazon-cloudwatchaws-xray

Monitor incoming requests based on subdomain in api gateway


I am using the wild card subdomain for API gateway, so the requests come from different subdomains.

eg: I get requests from abc.domain.com/api, def.domain.com/api, xyz.domain.com/api etc.

I have created dashboards and alarms in cloud watch for total request count coming to apigateway

enter image description here

Now I want to monitor the number of requests coming from each subdomain. I tried to filter the metric using a hostname, but it didn't work. I tried using AWS x-ray but am not able to get the exact count, it returns a sampled response.

I want to see for each subdomain whats the traffic. I can add a log for each API, but am not sure how to use it to create dashboards and alarms in cloud watch. If it's not possible in API gateway, is there any other way in which I can achieve this?

Any kind of help is appreciated.


Solution

  • If you have enabled access logs in API Gateway for APIs as explained here then it provides a domain infomation over which you can create custom query and visualize in a graph. For a sample query take a look here ( you would need grouping instead of a filter)

    After setting up the custom access logs, you can query against them to find more insights using the custom domain name (Note: you would need grouping instead of a filter)

    Go to CloudWatch Logs Insights console. In the log group text field, select the CloudWatch log group, APIGateway_CustomDomainLogs. Enter the following query.

    fields @timestamp, @message
    | filter DomainName like /(?i)(test.example.com)/