I have a c# aws lambda class with some code in its constructor. The lambda method itself is getting called every time I initiate it (with an SNS message post), however, I cannot see the constructor getting called (added log calls to observe from cloudwatch). The constructor only gets called at first launch (after the aws stack creation/update).
Is this an expected behaviour? Does aws somehow cache my lambda instances?
public class MyLambda
{
public MyLambda()
{
Console.WriteLine("Hello from ctor");
}
// This is the method assigned in CloudFormation
public bool Execute(SNSEvent snsEvent)
{
Console.WriteLine("Lambda called");
return true;
}
}
And here is the outcome in cloudwatch log; First time initiate Lambda:
Hello from ctor
Lambda called
And second time initiation of Lambda
Lambda called