-
-
Save mirez/b257078a8e76ffd4212c09a5a0c9751a to your computer and use it in GitHub Desktop.
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
public class LambdaApplication | |
{ | |
public string DoTheJob(string input) | |
{ | |
Console.WriteLine(input); | |
return input.ToUpper(); | |
} | |
} |
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
version: "3.8" | |
services: | |
lambda: | |
container_name: lambda | |
build: . | |
image: com.sciencevikinglabs.lambda | |
stdin_open: true | |
tty: true |
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
FROM public.ecr.aws/lambda/dotnet:5.0 | |
#You can alternately also pull these images from DockerHub amazon/aws-lambda-dotnet:5.0 | |
# Copy function code | |
COPY net5-lambda-template/bin/Debug/net5.0 ${LAMBDA_TASK_ROOT} | |
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | |
CMD [ "net5-lambda-template::net5_lambda_template.LambdaFunction::Handler" ] |
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
using Amazon.Lambda.Core; | |
using Microsoft.Extensions.DependencyInjection; | |
using net5_lambda_template.Core; | |
[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] | |
namespace net5_lambda_template | |
{ | |
public class LambdaFunction | |
{ | |
public string Handler(string input) | |
{ | |
var host = new LambdaHost(null); | |
var services = host.HostBuilder.Build().Services; | |
var app = services.GetService<LambdaApplication>(); | |
return app.DoTheJob(input); | |
} | |
} | |
} |
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
using Amazon.Lambda.Core; | |
[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] | |
namespace net5_lambda_template | |
{ | |
public class LambdaFunction | |
{ | |
public string Handler(string input) | |
{ | |
Console.WriteLine(input); | |
return input.ToUpper(); | |
} | |
} | |
} |
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
public class LambdaHost | |
{ | |
public IHostBuilder HostBuilder => GetHostBuilder(); | |
private IHostBuilder _hostBuilder; | |
private readonly string[] _hostArguments; | |
public LambdaHost(string[] args) | |
{ | |
_hostArguments = args; | |
} | |
private IHostBuilder GetHostBuilder() | |
{ | |
if (_hostBuilder != null) | |
return _hostBuilder; | |
_hostBuilder = Host.CreateDefaultBuilder(_hostArguments) | |
.ConfigureServices(ConfigureServicesInternal); | |
return _hostBuilder; | |
} | |
private static void ConfigureServicesInternal(IServiceCollection services) | |
{ | |
services.AddTransient<LambdaApplication>(); | |
} | |
} |
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
dotnet build .\net5-lambda-template.sln | |
docker-compose build | |
docker-compose run -p 9000:8080 lambda |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment