-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sample-apps/ec2-spot - does ec2Client
need to be static
?
#360
Comments
I'd like to know the answer to this as well. |
not the author of that sample code and not affiliated with this repo, nor with aws, but here's something from the docs regarding static members (using java but I think it's also applicable to dotnet):
https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html So it seems like the real value of using a static member comes from initializing it outside of the constructor (so that it only happens once across multiple lambda invocations). That is not the case in the c# code in the sample app. To fully achieve the goal of performance optimization, the member should be static but also the assignment needs to happen outside the constructor. Otoh, I don't see the same in the c# docs: https://docs.aws.amazon.com/lambda/latest/dg/csharp-handler.html Maybe that static member is a leftover from converting sample java code to c#? 🤷 |
hang on, it's a static constructor: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors |
As far as I can see, non static ctor is called only once too (at least in all tests I did) |
ec2Client
need to be static
?
I'm looking at this sample app and have a question why this sample uses a static modifier for
ec2Client
? As far as I understand, the intention is to use this client as singleton, but the same behavior will be reached ifec2Client
will be non static, won't it? Like:The text was updated successfully, but these errors were encountered: