Skip to content

Instantly share code, notes, and snippets.

@michaeldimoudis
Created April 27, 2019 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeldimoudis/c48cb22d1158f1fdf33ac7ff55b8a956 to your computer and use it in GitHub Desktop.
Save michaeldimoudis/c48cb22d1158f1fdf33ac7ff55b8a956 to your computer and use it in GitHub Desktop.
LocalEntryPoint.cs for custom resource serverless asp.net core web api
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