From 6bce362f7b55416956069df55482b2e8acc3d5b2 Mon Sep 17 00:00:00 2001 From: David Ruhmann Date: Wed, 31 Jan 2024 09:52:26 -0500 Subject: [PATCH 1/3] feat: add dotnet8 on al2 and al2023 --- manifest.json | 20 +++++++++++++ .../dotnet8_aot_on_provided_al2/Dockerfile | 14 ++++++++++ .../dotnet8_aot_on_provided_al2/build.sh | 20 +++++++++++++ .../src/Function.cs | 28 +++++++++++++++++++ .../src/LambdaPerf.csproj | 24 ++++++++++++++++ .../src/aws-lambda-tools-defaults.json | 8 ++++++ .../dotnet8_aot_on_provided_al2023/Dockerfile | 14 ++++++++++ .../dotnet8_aot_on_provided_al2023/build.sh | 20 +++++++++++++ .../src/Function.cs | 28 +++++++++++++++++++ .../src/LambdaPerf.csproj | 28 +++++++++++++++++++ .../src/aws-lambda-tools-defaults.json | 8 ++++++ 11 files changed, 212 insertions(+) create mode 100644 s3-uploader/runtimes/dotnet8_aot_on_provided_al2/Dockerfile create mode 100755 s3-uploader/runtimes/dotnet8_aot_on_provided_al2/build.sh create mode 100644 s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/Function.cs create mode 100644 s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/LambdaPerf.csproj create mode 100644 s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/aws-lambda-tools-defaults.json create mode 100644 s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/Dockerfile create mode 100755 s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/build.sh create mode 100644 s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/Function.cs create mode 100644 s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj create mode 100644 s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/aws-lambda-tools-defaults.json diff --git a/manifest.json b/manifest.json index 5c46e3655a..de9f6b9730 100644 --- a/manifest.json +++ b/manifest.json @@ -128,6 +128,26 @@ "baseImage": "public.ecr.aws/lambda/provided:al2" } }, + { + "displayName": "dotnet8 aot (prov.al2)", + "runtime": "provided.al2", + "handler": "bootstrap", + "path": "dotnet8_aot_on_provided_al2", + "architectures": ["x86_64", "arm64"], + "image": { + "baseImage": "public.ecr.aws/lambda/provided:al2" + } + }, + { + "displayName": "dotnet8 aot (prov.al2023)", + "runtime": "provided.al2023", + "handler": "bootstrap", + "path": "dotnet8_aot_on_provided_al2023", + "architectures": ["x86_64", "arm64"], + "image": { + "baseImage": "public.ecr.aws/lambda/provided:al2023" + } + }, { "displayName": "go1.x", "runtime": "go1.x", diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/Dockerfile b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/Dockerfile new file mode 100644 index 0000000000..24566e3dbd --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/Dockerfile @@ -0,0 +1,14 @@ +ARG IMAGE_TAG +FROM $IMAGE_TAG/amazonlinux:2 AS builder +ARG ARCH +WORKDIR /tmp +COPY src . +RUN yum update -y && yum install -y clang zlib-devel krb5-devel openssl-devel zip gzip tar wget +RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && chmod +x ./dotnet-install.sh && ./dotnet-install.sh --version latest +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 +RUN /root/.dotnet/dotnet publish --configuration Release --arch $ARCH --output /tmp/publish +RUN zip -j /tmp/code.zip /tmp/publish/bootstrap + +FROM scratch +COPY --from=builder /tmp/code.zip / +ENTRYPOINT ["/code.zip"] diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/build.sh b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/build.sh new file mode 100755 index 0000000000..2d02d40fef --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/build.sh @@ -0,0 +1,20 @@ +DIR_NAME="./runtimes/$1" + +if [ $2 = "x86_64" ]; then + ARCH="x64" + IMAGE_TAG="amd64" + PLATFORM="linux/amd64" +elif [ $2 = "arm64" ]; then + ARCH="arm64" + IMAGE_TAG="arm64v8" + PLATFORM="linux/arm64" +else + echo "The process architecture $2 is set incorrectly. The value can only be either x86_64 or arm64." + exit 1 +fi + +rm ${DIR_NAME}/code_${2}.zip 2> /dev/null + +docker build --platform ${PLATFORM} ${DIR_NAME} --build-arg ARCH=${ARCH} --build-arg IMAGE_TAG=${IMAGE_TAG} -t maxday/dotnet8_on_provided_al2_${2} +dockerId=$(docker create maxday/dotnet8_on_provided_al2_${2}) +docker cp $dockerId:/code.zip ${DIR_NAME}/code_${2}.zip diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/Function.cs b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/Function.cs new file mode 100644 index 0000000000..b2f36dd24d --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/Function.cs @@ -0,0 +1,28 @@ +using Amazon.Lambda.RuntimeSupport; +using Amazon.Lambda.Serialization.SystemTextJson; +using System.Text.Json.Serialization; + +namespace LambdaPerf; + +public class Function +{ + private static async Task Main() + { + await LambdaBootstrapBuilder.Create(FunctionHandler, new SourceGeneratorLambdaJsonSerializer()) + .Build() + .RunAsync(); + } + + public static StatusResponse FunctionHandler() + { + return new StatusResponse(StatusCode: 200); + } +} + +public record StatusResponse(int StatusCode); + +[JsonSerializable(typeof(StatusResponse))] +[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +public partial class LambdaFunctionJsonSerializerContext : JsonSerializerContext +{ +} diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/LambdaPerf.csproj b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/LambdaPerf.csproj new file mode 100644 index 0000000000..da247f728b --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/LambdaPerf.csproj @@ -0,0 +1,24 @@ + + + + Lambda + Exe + bootstrap + net8.0 + enable + enable + true + true + false + true + Speed + true + + + + + + + + + diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/aws-lambda-tools-defaults.json b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/aws-lambda-tools-defaults.json new file mode 100644 index 0000000000..471cd7a6d5 --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2/src/aws-lambda-tools-defaults.json @@ -0,0 +1,8 @@ +{ + "configuration": "Release", + "framework": "net8.0", + "function-runtime": "provided.al2", + "function-memory-size": 256, + "function-timeout": 30, + "function-handler": "bootstrap" +} diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/Dockerfile b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/Dockerfile new file mode 100644 index 0000000000..d4661a3724 --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/Dockerfile @@ -0,0 +1,14 @@ +ARG IMAGE_TAG +FROM $IMAGE_TAG/amazonlinux:2023 AS builder +ARG ARCH +WORKDIR /tmp +COPY src . +RUN yum update -y && yum install -y clang zlib-devel krb5-devel openssl-devel zip gzip tar wget +RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && chmod +x ./dotnet-install.sh && ./dotnet-install.sh --version latest +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 +RUN /root/.dotnet/dotnet publish --configuration Release --arch $ARCH --output /tmp/publish +RUN zip -j /tmp/code.zip /tmp/publish/bootstrap + +FROM scratch +COPY --from=builder /tmp/code.zip / +ENTRYPOINT ["/code.zip"] diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/build.sh b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/build.sh new file mode 100755 index 0000000000..3b4cc7b185 --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/build.sh @@ -0,0 +1,20 @@ +DIR_NAME="./runtimes/$1" + +if [ $2 = "x86_64" ]; then + ARCH="x64" + IMAGE_TAG="amd64" + PLATFORM="linux/amd64" +elif [ $2 = "arm64" ]; then + ARCH="arm64" + IMAGE_TAG="arm64v8" + PLATFORM="linux/arm64" +else + echo "The process architecture $2 is set incorrectly. The value can only be either x86_64 or arm64." + exit 1 +fi + +rm ${DIR_NAME}/code_${2}.zip 2> /dev/null + +docker build --platform ${PLATFORM} ${DIR_NAME} --build-arg ARCH=${ARCH} --build-arg IMAGE_TAG=${IMAGE_TAG} -t maxday/dotnet8_on_provided_al2023_${2} +dockerId=$(docker create maxday/dotnet8_on_provided_al2023_${2}) +docker cp $dockerId:/code.zip ${DIR_NAME}/code_${2}.zip diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/Function.cs b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/Function.cs new file mode 100644 index 0000000000..b2f36dd24d --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/Function.cs @@ -0,0 +1,28 @@ +using Amazon.Lambda.RuntimeSupport; +using Amazon.Lambda.Serialization.SystemTextJson; +using System.Text.Json.Serialization; + +namespace LambdaPerf; + +public class Function +{ + private static async Task Main() + { + await LambdaBootstrapBuilder.Create(FunctionHandler, new SourceGeneratorLambdaJsonSerializer()) + .Build() + .RunAsync(); + } + + public static StatusResponse FunctionHandler() + { + return new StatusResponse(StatusCode: 200); + } +} + +public record StatusResponse(int StatusCode); + +[JsonSerializable(typeof(StatusResponse))] +[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +public partial class LambdaFunctionJsonSerializerContext : JsonSerializerContext +{ +} diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj new file mode 100644 index 0000000000..e44be898b3 --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj @@ -0,0 +1,28 @@ + + + + Lambda + Exe + bootstrap + net8.0 + enable + enable + true + true + false + true + Speed + true + + + + + + + + + + + + + diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/aws-lambda-tools-defaults.json b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/aws-lambda-tools-defaults.json new file mode 100644 index 0000000000..471cd7a6d5 --- /dev/null +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/aws-lambda-tools-defaults.json @@ -0,0 +1,8 @@ +{ + "configuration": "Release", + "framework": "net8.0", + "function-runtime": "provided.al2", + "function-memory-size": 256, + "function-timeout": 30, + "function-handler": "bootstrap" +} From 154e3821dedaf3cdba7009e3da2890c985be0889 Mon Sep 17 00:00:00 2001 From: David Ruhmann Date: Wed, 31 Jan 2024 09:55:57 -0500 Subject: [PATCH 2/3] chore: remove unused ref --- .../dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj index e44be898b3..da247f728b 100644 --- a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/LambdaPerf.csproj @@ -15,10 +15,6 @@ true - - - - From 0fbffb574dc656c7b3ab2f76efe8b9545daf880e Mon Sep 17 00:00:00 2001 From: David Ruhmann Date: Wed, 31 Jan 2024 09:56:44 -0500 Subject: [PATCH 3/3] chore: 2023 runtime --- .../src/aws-lambda-tools-defaults.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/aws-lambda-tools-defaults.json b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/aws-lambda-tools-defaults.json index 471cd7a6d5..c73c187aad 100644 --- a/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/aws-lambda-tools-defaults.json +++ b/s3-uploader/runtimes/dotnet8_aot_on_provided_al2023/src/aws-lambda-tools-defaults.json @@ -1,7 +1,7 @@ { "configuration": "Release", "framework": "net8.0", - "function-runtime": "provided.al2", + "function-runtime": "provided.al2023", "function-memory-size": 256, "function-timeout": 30, "function-handler": "bootstrap"