Hosted AspNetCoreServer with BackgroundService? #1286
-
Can I run the AspNetCoreServer lambda with a BackgroundService (IHostedService)? If yes, what would this imply? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
You technically could but the |
Beta Was this translation helpful? Give feedback.
-
It sounds like you want a background service running all of the time. If that is your need Lambda probably isn't the best fit and you should run it as a Fargate container or something. Lambda is great for event based work loads like HTTP requests. |
Beta Was this translation helpful? Give feedback.
-
@normj During initialisation, I am preparing common objects to avoid doing same for each and every request. Initialisation contains following items
My idea is
I have following questions.
|
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
You technically could but the
IHostedService
would only run while a request is being processed. As soon as the request is complete the the Lambda compute environment would be frozen and there is no guarantees it would ever be unfrozen. For example Lambda could terminated the Lambda compute environment and spin up a new environment for the next event. So running anIHostedService
in a Lambda ASP.NET Core function has limited usefulness.