Skip to content

Commit

Permalink
Add dotnet 6 & 8 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
brianfeucht committed Jan 3, 2024
1 parent a2f28a9 commit 9ee96ed
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sample/SampleLambda-dotnet6/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
25 changes: 25 additions & 0 deletions sample/SampleLambda-dotnet6/HelloWorldHandler.cs
Original file line number Diff line number Diff line change
@@ -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<byte[]> 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");
}
}
}
27 changes: 27 additions & 0 deletions sample/SampleLambda-dotnet6/SampleLambda.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<None Remove="aws-lambda-tools-defaults.json" />
</ItemGroup>

<ItemGroup>
<Content Include="aws-lambda-tools-defaults.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="2.1.1" />
<PackageReference Include="HeadlessChromium.Puppeteer.Lambda.Dotnet" Version="1.1.0-dev" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="PuppeteerSharp" Version="13.0.1" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions sample/SampleLambda-dotnet6/aws-lambda-tools-defaults.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions sample/SampleLambda-dotnet6/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyLocalSharedSource" value="..\..\artifacts\" />
</packageSources>
</configuration>
10 changes: 10 additions & 0 deletions sample/SampleLambda-dotnet8/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
25 changes: 25 additions & 0 deletions sample/SampleLambda-dotnet8/HelloWorldHandler.cs
Original file line number Diff line number Diff line change
@@ -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<byte[]> 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");
}
}
}
27 changes: 27 additions & 0 deletions sample/SampleLambda-dotnet8/SampleLambda.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<None Remove="aws-lambda-tools-defaults.json" />
</ItemGroup>

<ItemGroup>
<Content Include="aws-lambda-tools-defaults.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="2.1.1" />
<PackageReference Include="HeadlessChromium.Puppeteer.Lambda.Dotnet" Version="1.1.0-dev" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="PuppeteerSharp" Version="13.0.1" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions sample/SampleLambda-dotnet8/aws-lambda-tools-defaults.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions sample/SampleLambda-dotnet8/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyLocalSharedSource" value="..\..\artifacts\" />
</packageSources>
</configuration>

0 comments on commit 9ee96ed

Please sign in to comment.