diff --git a/sample/SampleLambda-dotnet6/Dockerfile b/sample/SampleLambda-dotnet6/Dockerfile new file mode 100644 index 0000000..8ab1e99 --- /dev/null +++ b/sample/SampleLambda-dotnet6/Dockerfile @@ -0,0 +1,10 @@ +FROM public.ecr.aws/lambda/dotnet:6 + +# Set the image's internal work directory +WORKDIR /var/task + +# Copy function code +COPY "bin/Release/lambda-publish" . + +# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) +CMD [ "SampleLambda::SampleLambda.HelloWorldHandler::Handle" ] \ No newline at end of file diff --git a/sample/SampleLambda-dotnet6/HelloWorldHandler.cs b/sample/SampleLambda-dotnet6/HelloWorldHandler.cs new file mode 100644 index 0000000..d838175 --- /dev/null +++ b/sample/SampleLambda-dotnet6/HelloWorldHandler.cs @@ -0,0 +1,25 @@ +using Amazon.Lambda.Core; +using HeadlessChromium.Puppeteer.Lambda.Dotnet; +using Microsoft.Extensions.Logging; + +namespace SampleLambda +{ + public class HelloWorldHandler + { + [LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] + public async Task Handle(ILambdaContext context) + { + var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); + var browserLauncher = new HeadlessChromiumPuppeteerLauncher(loggerFactory); + + await using (var browser = await browserLauncher.LaunchAsync()) + await using (var page = await browser.NewPageAsync()) + { + await page.GoToAsync("https://www.google.com"); + await page.ScreenshotAsync("./google.png"); + } + + return await File.ReadAllBytesAsync("./google.png"); + } + } +} \ No newline at end of file diff --git a/sample/SampleLambda-dotnet6/SampleLambda.csproj b/sample/SampleLambda-dotnet6/SampleLambda.csproj new file mode 100644 index 0000000..5575025 --- /dev/null +++ b/sample/SampleLambda-dotnet6/SampleLambda.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + + + + + + + + + PreserveNewest + + + + + + + + + + + + diff --git a/sample/SampleLambda-dotnet6/aws-lambda-tools-defaults.json b/sample/SampleLambda-dotnet6/aws-lambda-tools-defaults.json new file mode 100644 index 0000000..937a9b1 --- /dev/null +++ b/sample/SampleLambda-dotnet6/aws-lambda-tools-defaults.json @@ -0,0 +1,10 @@ +{ + "configuration": "Release", + "framework": "net6.0", + "function-runtime": "dotnet6", + "function-memory-size": 1536, + "function-timeout": 60, + "function-handler": "SampleLambda::SampleLambda.HelloWorldHandler::Handle", + "package-type": "image", + "docker-host-build-output-dir": "./bin/Release/lambda-publish" +} diff --git a/sample/SampleLambda-dotnet6/nuget.config b/sample/SampleLambda-dotnet6/nuget.config new file mode 100644 index 0000000..9748ac4 --- /dev/null +++ b/sample/SampleLambda-dotnet6/nuget.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sample/SampleLambda-dotnet8/Dockerfile b/sample/SampleLambda-dotnet8/Dockerfile new file mode 100644 index 0000000..1787abe --- /dev/null +++ b/sample/SampleLambda-dotnet8/Dockerfile @@ -0,0 +1,10 @@ +FROM public.ecr.aws/lambda/dotnet:8-preview + +# Set the image's internal work directory +WORKDIR /var/task + +# Copy function code +COPY "bin/Release/lambda-publish" . + +# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) +CMD [ "SampleLambda::SampleLambda.HelloWorldHandler::Handle" ] \ No newline at end of file diff --git a/sample/SampleLambda-dotnet8/HelloWorldHandler.cs b/sample/SampleLambda-dotnet8/HelloWorldHandler.cs new file mode 100644 index 0000000..d838175 --- /dev/null +++ b/sample/SampleLambda-dotnet8/HelloWorldHandler.cs @@ -0,0 +1,25 @@ +using Amazon.Lambda.Core; +using HeadlessChromium.Puppeteer.Lambda.Dotnet; +using Microsoft.Extensions.Logging; + +namespace SampleLambda +{ + public class HelloWorldHandler + { + [LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] + public async Task Handle(ILambdaContext context) + { + var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); + var browserLauncher = new HeadlessChromiumPuppeteerLauncher(loggerFactory); + + await using (var browser = await browserLauncher.LaunchAsync()) + await using (var page = await browser.NewPageAsync()) + { + await page.GoToAsync("https://www.google.com"); + await page.ScreenshotAsync("./google.png"); + } + + return await File.ReadAllBytesAsync("./google.png"); + } + } +} \ No newline at end of file diff --git a/sample/SampleLambda-dotnet8/SampleLambda.csproj b/sample/SampleLambda-dotnet8/SampleLambda.csproj new file mode 100644 index 0000000..7d4e8cd --- /dev/null +++ b/sample/SampleLambda-dotnet8/SampleLambda.csproj @@ -0,0 +1,27 @@ + + + + net8.0 + enable + enable + + + + + + + + + PreserveNewest + + + + + + + + + + + + diff --git a/sample/SampleLambda-dotnet8/aws-lambda-tools-defaults.json b/sample/SampleLambda-dotnet8/aws-lambda-tools-defaults.json new file mode 100644 index 0000000..51af147 --- /dev/null +++ b/sample/SampleLambda-dotnet8/aws-lambda-tools-defaults.json @@ -0,0 +1,10 @@ +{ + "configuration": "Release", + "framework": "net8.0", + "function-runtime": "dotnet8", + "function-memory-size": 1536, + "function-timeout": 60, + "function-handler": "SampleLambda::SampleLambda.HelloWorldHandler::Handle", + "package-type": "image", + "docker-host-build-output-dir": "./bin/Release/lambda-publish" +} diff --git a/sample/SampleLambda-dotnet8/nuget.config b/sample/SampleLambda-dotnet8/nuget.config new file mode 100644 index 0000000..9748ac4 --- /dev/null +++ b/sample/SampleLambda-dotnet8/nuget.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file