'Handle Interceptor in lambda python

I have a lambda that makes a request to an API and then returns it to the client. I need to generate an object with the lambda input event along with the response of the request made to api and later send it to an SNS topic. This solution aims to create an audit base recording who made the request and what they got in response.

In this case I thought about passing the event to the method that executes the api call and creating the object with the request and response in it. Then I would take this object and send it to a layer, and in that layer I would have the method to send it to the topic.

I thought about doing it by layer so that the other lambdas take advantage of the submission method for the topic.

Does this solution make sense? Is there any other way to build it?

I know Spring has the handlerInterceptor, but I haven't seen something similar for python and I don't know if it would make sense in the context of lambdas.

Anyway thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source