This repository has been archived by the owner on Jan 15, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 429
Add support for dotnet 6 #359
Open
robhughadams
wants to merge
2
commits into
lambci:master
Choose a base branch
from
robhughadams:358-add-dotnet-6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
using Amazon.Lambda.Core; | ||
using Amazon.S3; | ||
|
||
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] | ||
|
||
namespace dump_dotnet6 | ||
{ | ||
public class Function | ||
{ | ||
/// <summary> | ||
/// Lambda function to dump the container directories /var/lang | ||
/// and /var/runtime and upload the resulting archive to S3 | ||
/// </summary> | ||
/// <returns></returns> | ||
public async Task<string> FunctionHandler(object invokeEvent, ILambdaContext context) | ||
{ | ||
string filename = "dotnet6.0.tgz"; | ||
string cmd = $"tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read /var/runtime /var/lang"; | ||
|
||
Console.WriteLine($"invokeEvent: {invokeEvent}"); | ||
Console.WriteLine($"context.RemainingTime: {context.RemainingTime}"); | ||
|
||
Console.WriteLine("Parent cmdline:"); | ||
Console.WriteLine(File.ReadAllText("/proc/1/cmdline").Replace("\0", " ")); | ||
|
||
Console.WriteLine("Parent env:"); | ||
RunShell("xargs --null --max-args=1 < /proc/1/environ"); | ||
|
||
Console.WriteLine("This cmdline:"); | ||
Console.WriteLine(File.ReadAllText($"/proc/{Process.GetCurrentProcess().Id}/cmdline").Replace("\0", " ")); | ||
|
||
Console.WriteLine("This env:"); | ||
RunShell($"xargs --null --max-args=1 < /proc/{Process.GetCurrentProcess().Id}/environ"); | ||
|
||
Console.WriteLine($"Current working directory: {Directory.GetCurrentDirectory()}"); | ||
|
||
RunShell(cmd); | ||
|
||
Console.WriteLine("Zipping done! Uploading..."); | ||
|
||
var s3Client = new AmazonS3Client(); | ||
var response = await s3Client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest | ||
{ | ||
BucketName = "lambci", | ||
Key = $"fs/{filename}", | ||
FilePath = $"/tmp/{filename}", | ||
CannedACL = S3CannedACL.PublicRead, | ||
}); | ||
|
||
Console.WriteLine("Uploading done!"); | ||
|
||
return response.HttpStatusCode.ToString(); | ||
} | ||
|
||
private static Process RunShell(string cmd) | ||
{ | ||
var escapedArgs = cmd.Replace("\"", "\\\""); | ||
var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = "/bin/sh", | ||
Arguments = $"-c \"{escapedArgs}\"", | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
process.Start(); | ||
process.WaitForExit(); | ||
return process; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"configuration": "Release", | ||
"framework": "net6.0", | ||
"function-runtime": "dotnet6.0", | ||
"function-memory-size": 3008, | ||
"function-timeout": 60, | ||
"function-handler": "dump_dotnet6::dump_dotnet6.Function::FunctionHandler" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>dump_dotnet6</RootNamespace> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AssemblyName>dump_dotnet6</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.Core" Version="1.1.0" /> | ||
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.7.0" /> | ||
<PackageReference Include="AWSSDK.S3" Version="3.3.108.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 provided.al2 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" | ||
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 provided.al2 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1 dotnet6.0" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM lambci/lambda:dotnet6 | ||
|
||
FROM lambci/lambda-base-2:build | ||
|
||
# Run: docker run --rm --entrypoint dotnet lambci/lambda:dotnet6 --info | ||
# Check https://dotnet.microsoft.com/download/dotnet-core/6.0 for versions | ||
ENV DOTNET_ROOT=/var/lang/bin | ||
ENV PATH=/root/.dotnet/tools:$DOTNET_ROOT:$PATH \ | ||
LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ | ||
AWS_EXECUTION_ENV=AWS_Lambda_dotnet6 \ | ||
DOTNET_SDK_VERSION=6.0.201 \ | ||
DOTNET_CLI_TELEMETRY_OPTOUT=1 \ | ||
NUGET_XMLDOC_MODE=skip | ||
|
||
COPY --from=0 /var/runtime /var/runtime | ||
COPY --from=0 /var/lang /var/lang | ||
COPY --from=0 /var/rapid /var/rapid | ||
|
||
RUN curl -L https://dot.net/v1/dotnet-install.sh | bash -s -- -v $DOTNET_SDK_VERSION -i $DOTNET_ROOT && \ | ||
mkdir /tmp/warmup && \ | ||
cd /tmp/warmup && \ | ||
dotnet new && \ | ||
cd / && \ | ||
rm -rf /tmp/warmup /tmp/NuGetScratch /tmp/.dotnet | ||
|
||
# Add these as a separate layer as they get updated frequently | ||
RUN pipx install awscli==1.* && \ | ||
pipx install aws-lambda-builders==1.2.0 && \ | ||
pipx install aws-sam-cli==1.15.0 && \ | ||
dotnet tool install --global Amazon.Lambda.Tools --version 4.0.0 | ||
|
||
CMD ["dotnet", "build"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM lambci/lambda-base | ||
|
||
RUN curl https://lambci.s3.amazonaws.com/fs/dotnet6.tgz | tar -zx -C /opt | ||
|
||
|
||
FROM lambci/lambda:provided | ||
|
||
|
||
FROM lambci/lambda-base-2 | ||
|
||
ENV PATH=/var/lang/bin:$PATH \ | ||
LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ | ||
AWS_EXECUTION_ENV=AWS_Lambda_dotnet6 | ||
|
||
COPY --from=0 /opt/* /var/ | ||
|
||
COPY --from=1 /var/runtime/init /var/rapid/init | ||
|
||
USER sbx_user1051 | ||
|
||
ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Compile with: | ||
// docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnet6.0 dotnet publish -c Release -o pub | ||
|
||
// Run with: | ||
// docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnet6.0 test::test.Function::FunctionHandler '{"some": "event"}' | ||
|
||
using System; | ||
using System.Collections; | ||
using Amazon.Lambda.Core; | ||
|
||
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] | ||
|
||
namespace test | ||
{ | ||
public class Function | ||
{ | ||
public string FunctionHandler(object inputEvent, ILambdaContext context) | ||
{ | ||
Console.WriteLine($"inputEvent: {inputEvent}"); | ||
Console.WriteLine($"RemainingTime: {context.RemainingTime}"); | ||
|
||
foreach (DictionaryEntry kv in Environment.GetEnvironmentVariables()) | ||
{ | ||
Console.WriteLine($"{kv.Key}={kv.Value}"); | ||
} | ||
|
||
return "Hello World!"; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# .NET 6.0 docker-lambda example | ||
|
||
```sh | ||
# Will place the compiled code in `./pub` | ||
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnet6.0 dotnet publish -c Release -o pub | ||
|
||
# Then you can run using that as the task directory | ||
docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnet6.0 test::test.Function::FunctionHandler '{"some": "event"}' | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.Core" Version="1.1.0" /> | ||
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.7.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test.csproj", "{0A83D120-2336-4F30-86F1-DC045C3C9B90}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0A83D120-2336-4F30-86F1-DC045C3C9B90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0A83D120-2336-4F30-86F1-DC045C3C9B90}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0A83D120-2336-4F30-86F1-DC045C3C9B90}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0A83D120-2336-4F30-86F1-DC045C3C9B90}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should runtime name be
dotnet6
- this is how AWS has it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I've updated.