0

I need to execute some Lambda function for collecting statistics before any method from API gateway is called. Is it possible to achieve this in AWS? I am using proxy integration in Api Gateway.

2 Answers 2

1

This can be done in the CDN level if you have one. If you are using cloudfront then the steps could be,

  1. Create a regional endpoint.
  2. Set up own cloudfron distribution - https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cloudfront-distribution/
  3. Handle the request with Lambda@Edge, add a trigger for Origin Request.https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-cloudfront-trigger-events.html
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your idea. Unfortunately your solution is possible to implement only in "US East (N. Virginia)" region -> docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/… I can't change the region to US East (N. Virginia) so I need to look for other solutions.
may I know what kind of statistics are you looking to measure?
I want to count API requests which contain certain data, i.e. API requests which have "personId" parameter set in body. I want to store these statistics in DynamoDB table.
1

Few Ideas,

  • If the requests may be whitelisted and blacklisted based on the parameter, lambda custom authorizor can be used to plug in the logic.
  • if the statistics don't influence the business logic, then cloudwatch logs can be parsed (log insights or cloudwatch rules) and the statistics can be gathered.
  • Aggregation pattern can be used for the statistics- either Gateway or Lambda level , but this will add additional latency for each requests.

1 Comment

Unfortunately CloudWatch is not an option for me. I need to extract tenantId field from the request. This is needed for my statistics.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.