Created
April 27, 2019 10:48
-
-
Save michaeldimoudis/c48cb22d1158f1fdf33ac7ff55b8a956 to your computer and use it in GitHub Desktop.
LocalEntryPoint.cs for custom resource serverless asp.net core web api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AWSServerless1 | |
{ | |
/// <summary> | |
/// The Main function can be used to run the ASP.NET Core application locally using the Kestrel webserver. | |
/// It is now also the main entry point for the custom runtime. | |
/// </summary> | |
public class LocalEntryPoint | |
{ | |
private static readonly LambdaEntryPoint LambdaEntryPoint = new LambdaEntryPoint(); | |
private static readonly Func<APIGatewayProxyRequest, ILambdaContext, Task<APIGatewayProxyResponse>> Func = LambdaEntryPoint.FunctionHandlerAsync; | |
public static async Task Main(string[] args) | |
{ | |
#if DEBUG | |
BuildWebHost(args).Run(); | |
#else | |
// Wrap the FunctionHandler method in a form that LambdaBootstrap can work with. | |
using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(Func, new JsonSerializer())) | |
// Instantiate a LambdaBootstrap and run it. | |
// It will wait for invocations from AWS Lambda and call the handler function for each one. | |
using (var bootstrap = new LambdaBootstrap(handlerWrapper)) | |
{ | |
await bootstrap.RunAsync(); | |
} | |
#endif | |
} | |
public static IWebHost BuildWebHost(string[] args) => | |
WebHost.CreateDefaultBuilder(args) | |
.UseStartup<Startup>() | |
.Build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment