Skip to content
This repository was archived by the owner on Jan 15, 2023. It is now read-only.

Commit 70bd0ec

Browse files
committed
Add support for dotnet 6
1 parent f6b4765 commit 70bd0ec

File tree

13 files changed

+256
-10
lines changed

13 files changed

+256
-10
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ base/dump-dotnetcore21/bin
1818
base/dump-dotnetcore21/obj
1919
base/dump-dotnetcore31/bin
2020
base/dump-dotnetcore31/obj
21+
base/dump-dotnet6/bin
22+
base/dump-dotnet6/obj
2123
base/dump-providedal2/bootstrap
2224
base/dump-providedal2/bootstrap.zip
2325
dotnetcore2.0/run/MockBootstraps/bin
@@ -34,6 +36,9 @@ examples/dotnetcore2.1/pub
3436
examples/dotnetcore3.1/bin
3537
examples/dotnetcore3.1/obj
3638
examples/dotnetcore3.1/pub
39+
examples/dotnet6.0/bin
40+
examples/dotnet6.0/obj
41+
examples/dotnet6.0/pub
3742
examples/java/bin
3843
examples/java/build
3944
examples/go1.x/handler

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ the [AWS CLI](https://aws.amazon.com/cli/).
1717

1818
## Contents
1919

20-
* [Usage](#usage)
21-
* [Run Examples](#run-examples)
22-
* [Build Examples](#build-examples)
23-
* [Using a Dockerfile to build](#using-a-dockerfile-to-build)
24-
* [Docker tags](#docker-tags)
25-
* [Verifying images](#verifying-images)
26-
* [Environment variables](#environment-variables)
27-
* [Build environment](#build-environment)
28-
* [Questions](#questions)
20+
- [docker-lambda](#docker-lambda)
21+
- [Contents](#contents)
22+
- [Usage](#usage)
23+
- [Running Lambda functions](#running-lambda-functions)
24+
- [Running in "stay-open" API mode](#running-in-stay-open-api-mode)
25+
- [Developing in "stay-open" mode](#developing-in-stay-open-mode)
26+
- [Building Lambda functions](#building-lambda-functions)
27+
- [Run Examples](#run-examples)
28+
- [Build Examples](#build-examples)
29+
- [Using a Dockerfile to build](#using-a-dockerfile-to-build)
30+
- [Node.js module](#nodejs-module)
31+
- [Docker tags](#docker-tags)
32+
- [Verifying images](#verifying-images)
33+
- [Environment variables](#environment-variables)
34+
- [Build environment](#build-environment)
35+
- [Questions](#questions)
2936

3037
---
3138

@@ -313,6 +320,7 @@ These follow the Lambda runtime names:
313320
- `java8.al2`
314321
- `java11`
315322
- `go1.x`
323+
- `dotnet6`
316324
- `dotnetcore2.0`
317325
- `dotnetcore2.1`
318326
- `dotnetcore3.1`
@@ -333,6 +341,7 @@ These follow the Lambda runtime names:
333341
- `build-java8.al2`
334342
- `build-java11`
335343
- `build-go1.x`
344+
- `build-dotnet6`
336345
- `build-dotnetcore2.0`
337346
- `build-dotnetcore2.1`
338347
- `build-dotnetcore3.1`

base/dump-dotnet6/Function.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
6+
using Amazon.Lambda.Core;
7+
using Amazon.S3;
8+
9+
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
10+
11+
namespace dump_dotnet6
12+
{
13+
public class Function
14+
{
15+
/// <summary>
16+
/// Lambda function to dump the container directories /var/lang
17+
/// and /var/runtime and upload the resulting archive to S3
18+
/// </summary>
19+
/// <returns></returns>
20+
public async Task<string> FunctionHandler(object invokeEvent, ILambdaContext context)
21+
{
22+
string filename = "dotnet6.0.tgz";
23+
string cmd = $"tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read /var/runtime /var/lang";
24+
25+
Console.WriteLine($"invokeEvent: {invokeEvent}");
26+
Console.WriteLine($"context.RemainingTime: {context.RemainingTime}");
27+
28+
Console.WriteLine("Parent cmdline:");
29+
Console.WriteLine(File.ReadAllText("/proc/1/cmdline").Replace("\0", " "));
30+
31+
Console.WriteLine("Parent env:");
32+
RunShell("xargs --null --max-args=1 < /proc/1/environ");
33+
34+
Console.WriteLine("This cmdline:");
35+
Console.WriteLine(File.ReadAllText($"/proc/{Process.GetCurrentProcess().Id}/cmdline").Replace("\0", " "));
36+
37+
Console.WriteLine("This env:");
38+
RunShell($"xargs --null --max-args=1 < /proc/{Process.GetCurrentProcess().Id}/environ");
39+
40+
Console.WriteLine($"Current working directory: {Directory.GetCurrentDirectory()}");
41+
42+
RunShell(cmd);
43+
44+
Console.WriteLine("Zipping done! Uploading...");
45+
46+
var s3Client = new AmazonS3Client();
47+
var response = await s3Client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest
48+
{
49+
BucketName = "lambci",
50+
Key = $"fs/{filename}",
51+
FilePath = $"/tmp/{filename}",
52+
CannedACL = S3CannedACL.PublicRead,
53+
});
54+
55+
Console.WriteLine("Uploading done!");
56+
57+
return response.HttpStatusCode.ToString();
58+
}
59+
60+
private static Process RunShell(string cmd)
61+
{
62+
var escapedArgs = cmd.Replace("\"", "\\\"");
63+
var process = new Process
64+
{
65+
StartInfo = new ProcessStartInfo
66+
{
67+
FileName = "/bin/sh",
68+
Arguments = $"-c \"{escapedArgs}\"",
69+
UseShellExecute = false,
70+
CreateNoWindow = true,
71+
}
72+
};
73+
process.Start();
74+
process.WaitForExit();
75+
return process;
76+
}
77+
}
78+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"configuration": "Release",
3+
"framework": "net6.0",
4+
"function-runtime": "dotnet6.0",
5+
"function-memory-size": 3008,
6+
"function-timeout": 60,
7+
"function-handler": "dump_dotnet6::dump_dotnet6.Function::FunctionHandler"
8+
}

base/dump-dotnet6/dump-dotnet6.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<RootNamespace>dump_dotnet6</RootNamespace>
6+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
7+
<AssemblyName>dump_dotnet6</AssemblyName>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Amazon.Lambda.Core" Version="1.1.0" />
12+
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.7.0" />
13+
<PackageReference Include="AWSSDK.S3" Version="3.3.108.2" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.2.0" />
18+
</ItemGroup>
19+
20+
</Project>

base/runtimes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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"
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"

base/test-all.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ cd ${EXAMPLES_DIR}/dotnetcore3.1
5151
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore3.1 dotnet publish -c Release -o pub
5252
docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore3.1 test::test.Function::FunctionHandler '{"some": "event"}'
5353

54+
cd ${EXAMPLES_DIR}/dotnet6.0
55+
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnet6.0 dotnet publish -c Release -o pub
56+
docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnet6.0 test::test.Function::FunctionHandler '{"some": "event"}'
57+
5458
cd ${EXAMPLES_DIR}/go1.x
5559
docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'go mod download && go build handler.go'
5660
docker run --rm -v "$PWD":/var/task lambci/lambda:go1.x handler '{"Records": []}'

dotnet6/build/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM lambci/lambda:dotnet6
2+
3+
FROM lambci/lambda-base-2:build
4+
5+
# Run: docker run --rm --entrypoint dotnet lambci/lambda:dotnet6 --info
6+
# Check https://dotnet.microsoft.com/download/dotnet-core/6.0 for versions
7+
ENV DOTNET_ROOT=/var/lang/bin
8+
ENV PATH=/root/.dotnet/tools:$DOTNET_ROOT:$PATH \
9+
LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \
10+
AWS_EXECUTION_ENV=AWS_Lambda_dotnet6 \
11+
DOTNET_SDK_VERSION=6.0.201 \
12+
DOTNET_CLI_TELEMETRY_OPTOUT=1 \
13+
NUGET_XMLDOC_MODE=skip
14+
15+
COPY --from=0 /var/runtime /var/runtime
16+
COPY --from=0 /var/lang /var/lang
17+
COPY --from=0 /var/rapid /var/rapid
18+
19+
RUN curl -L https://dot.net/v1/dotnet-install.sh | bash -s -- -v $DOTNET_SDK_VERSION -i $DOTNET_ROOT && \
20+
mkdir /tmp/warmup && \
21+
cd /tmp/warmup && \
22+
dotnet new && \
23+
cd / && \
24+
rm -rf /tmp/warmup /tmp/NuGetScratch /tmp/.dotnet
25+
26+
# Add these as a separate layer as they get updated frequently
27+
RUN pipx install awscli==1.* && \
28+
pipx install aws-lambda-builders==1.2.0 && \
29+
pipx install aws-sam-cli==1.15.0 && \
30+
dotnet tool install --global Amazon.Lambda.Tools --version 4.0.0
31+
32+
CMD ["dotnet", "build"]

dotnet6/run/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM lambci/lambda-base
2+
3+
RUN curl https://lambci.s3.amazonaws.com/fs/dotnet6.tgz | tar -zx -C /opt
4+
5+
6+
FROM lambci/lambda:provided
7+
8+
9+
FROM lambci/lambda-base-2
10+
11+
ENV PATH=/var/lang/bin:$PATH \
12+
LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \
13+
AWS_EXECUTION_ENV=AWS_Lambda_dotnet6
14+
15+
COPY --from=0 /opt/* /var/
16+
17+
COPY --from=1 /var/runtime/init /var/rapid/init
18+
19+
USER sbx_user1051
20+
21+
ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"]

examples/dotnet6.0/Function.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Compile with:
2+
// docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnet6.0 dotnet publish -c Release -o pub
3+
4+
// Run with:
5+
// docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnet6.0 test::test.Function::FunctionHandler '{"some": "event"}'
6+
7+
using System;
8+
using System.Collections;
9+
using Amazon.Lambda.Core;
10+
11+
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
12+
13+
namespace test
14+
{
15+
public class Function
16+
{
17+
public string FunctionHandler(object inputEvent, ILambdaContext context)
18+
{
19+
Console.WriteLine($"inputEvent: {inputEvent}");
20+
Console.WriteLine($"RemainingTime: {context.RemainingTime}");
21+
22+
foreach (DictionaryEntry kv in Environment.GetEnvironmentVariables())
23+
{
24+
Console.WriteLine($"{kv.Key}={kv.Value}");
25+
}
26+
27+
return "Hello World!";
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)