You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I currently have a lambda handler class that has multiple entry points, each with its own lambda function.
The issue that I'm currently facing is the need to do some cleanup code after each invocation of any of the lambdas, so I tried to implement IDisposable on my function handler class, but it seems that is it never invoked, so currently the only option is to manually wrap all my code in try-finally clauses which is a bit messy.
In my current case I need to ensure NLog flushes all the logs to the console (ergo CloudWatch), but I imagine there can be many similar use cases for doing cleanup logic after each request.
The instance of the class containing the Lambda functions will stay around for the lifetime of the Lambda compute environment. This is great for maintaining cached state between function innovation but in your case that does mean for your case the class won't be disposed after an invocation.
Your options are like you said wrap each function in a try finally or put your functions in a separate class in then in the exposed Lambda function create that class in a using block and then invoke the real implementation. Here is a rough sketch of what I mean.
Activity
normj commentedon Jun 15, 2017
The instance of the class containing the Lambda functions will stay around for the lifetime of the Lambda compute environment. This is great for maintaining cached state between function innovation but in your case that does mean for your case the class won't be disposed after an invocation.
Your options are like you said wrap each function in a try finally or put your functions in a separate class in then in the exposed Lambda function create that class in a using block and then invoke the real implementation. Here is a rough sketch of what I mean.
normj commentedon Jun 22, 2017
Closing as I believe this is answered. If not feel free to reopen.