Skip to content

Commit

Permalink
Add dotnetcore3.1 runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mhart committed Mar 27, 2020
1 parent ec4828c commit ab9d48d
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ base/dump-dotnetcore20/bin
base/dump-dotnetcore20/obj
base/dump-dotnetcore21/bin
base/dump-dotnetcore21/obj
base/dump-dotnetcore31/bin
base/dump-dotnetcore31/obj
dotnetcore2.0/run/MockBootstraps/bin
dotnetcore2.0/run/MockBootstraps/obj
dotnetcore2.1/run/MockBootstraps/bin
Expand All @@ -25,6 +27,9 @@ examples/dotnetcore2.0/pub
examples/dotnetcore2.1/bin
examples/dotnetcore2.1/obj
examples/dotnetcore2.1/pub
examples/dotnetcore3.1/bin
examples/dotnetcore3.1/obj
examples/dotnetcore3.1/pub
examples/java/bin
examples/java/build
examples/go1.x/handler
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:go1.x my_handler
# http://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:java11 org.myorg.MyHandler

# Test on .NET Core 2.1 given a test.dll assembly in the current directory,
# Test on .NET Core 3.1 given a test.dll assembly in the current directory,
# a class named Function with a FunctionHandler method, and a custom event
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:dotnetcore2.1 test::test.Function::FunctionHandler '{"some": "event"}'
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:dotnetcore3.1 test::test.Function::FunctionHandler '{"some": "event"}'

# Test with a provided runtime (assumes you have a `bootstrap` executable in the current directory)
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:provided handler '{"some": "event"}'
Expand Down Expand Up @@ -233,7 +233,7 @@ docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x go mod downl

# For .NET Core, this will publish the compiled code to `./pub`,
# which you can then use to run with `-v "$PWD"/pub:/var/task`
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.1 dotnet publish -c Release -o pub
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore3.1 dotnet publish -c Release -o pub

# Run custom commands on a build container
docker run --rm lambci/lambda:build-python3.8 aws --version
Expand Down Expand Up @@ -312,6 +312,7 @@ These follow the Lambda runtime names:
- `go1.x`
- `dotnetcore2.0`
- `dotnetcore2.1`
- `dotnetcore3.1`
- `provided`
- `build-nodejs4.3`
- `build-nodejs6.10`
Expand All @@ -329,6 +330,7 @@ These follow the Lambda runtime names:
- `build-go1.x`
- `build-dotnetcore2.0`
- `build-dotnetcore2.1`
- `build-dotnetcore3.1`
- `build-provided`

## Verifying images
Expand Down
2 changes: 1 addition & 1 deletion base/build-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 ruby2.7 java8 java11 dotnetcore2.0 dotnetcore2.1"
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 ruby2.7 java8 java11 dotnetcore2.0 dotnetcore2.1 dotnetcore3.1"

TOP_DIR="${PWD}/.."

Expand Down
78 changes: 78 additions & 0 deletions base/dump-dotnetcore31/Function.cs
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_dotnetcore31
{
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 = "dotnetcore3.1.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;
}
}
}
8 changes: 8 additions & 0 deletions base/dump-dotnetcore31/aws-lambda-tools-defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"configuration": "Release",
"framework": "netcoreapp3.1",
"function-runtime": "dotnetcore3.1",
"function-memory-size": 3008,
"function-timeout": 60,
"function-handler": "dump_dotnetcore31::dump_dotnetcore31.Function::FunctionHandler"
}
20 changes: 20 additions & 0 deletions base/dump-dotnetcore31/dump-dotnetcore31.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>dump_dotnetcore31</RootNamespace>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>dump_dotnetcore31</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>
2 changes: 1 addition & 1 deletion base/dump.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="node43 node610 node810 node10x node12x python27 python36 python37 python38 ruby25 ruby27 java8 java11 go1x dotnetcore20 dotnetcore21 provided"
RUNTIMES="node43 node610 node810 node10x node12x python27 python36 python37 python38 ruby25 ruby27 java8 java11 go1x dotnetcore20 dotnetcore21 dotnetcore31 provided"

for RUNTIME in $RUNTIMES; do
echo $RUNTIME
Expand Down
2 changes: 1 addition & 1 deletion base/publish-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 ruby2.7 java8 java11 dotnetcore2.0 dotnetcore2.1"
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 ruby2.7 java8 java11 dotnetcore2.0 dotnetcore2.1 dotnetcore3.1"

echo -n "Enter repository passphrase: "
read -s DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE
Expand Down
2 changes: 1 addition & 1 deletion base/tag-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 ruby2.7 java8 java11 dotnetcore2.0 dotnetcore2.1"
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 ruby2.7 java8 java11 dotnetcore2.0 dotnetcore2.1 dotnetcore3.1"

git tag -f latest

Expand Down
4 changes: 4 additions & 0 deletions base/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ cd ${EXAMPLES_DIR}/dotnetcore2.1
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.1 dotnet publish -c Release -o pub
docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore2.1 test::test.Function::FunctionHandler '{"some": "event"}'

cd ${EXAMPLES_DIR}/dotnetcore3.1
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore3.1 dotnet publish -c Release -o pub
docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore3.1 test::test.Function::FunctionHandler '{"some": "event"}'

cd ${EXAMPLES_DIR}/go1.x
docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'go mod download && go build handler.go'
docker run --rm -v "$PWD":/var/task lambci/lambda:go1.x handler '{"Records": []}'
Expand Down
26 changes: 26 additions & 0 deletions dotnetcore3.1/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM lambci/lambda-base-2:build

# Run: docker run --rm --entrypoint dotnet lambci/lambda:dotnetcore3.1 --info
# Check https://dotnet.microsoft.com/download/dotnet-core/3.1 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_dotnetcore3.1 \
DOTNET_SDK_VERSION=3.1.201 \
DOTNET_CLI_TELEMETRY_OPTOUT=1 \
NUGET_XMLDOC_MODE=skip

RUN rm -rf /var/runtime /var/lang && \
curl https://lambci.s3.amazonaws.com/fs/dotnetcore3.1.tgz | tar -zx -C / && \
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 pip install -U awscli boto3 aws-sam-cli==0.46.2 aws-lambda-builders==0.8.0 --no-cache-dir && \
dotnet tool install --global Amazon.Lambda.Tools --version 3.3.1

CMD ["dotnet", "build"]
21 changes: 21 additions & 0 deletions dotnetcore3.1/run/Dockerfile
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/dotnetcore3.1.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_dotnetcore3.1

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"]
30 changes: 30 additions & 0 deletions examples/dotnetcore3.1/Function.cs
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-dotnetcore3.1 dotnet publish -c Release -o pub

// Run with:
// docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore3.1 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!";
}
}
}
9 changes: 9 additions & 0 deletions examples/dotnetcore3.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# .NET Core 3.1 docker-lambda example

```sh
# Will place the compiled code in `./pub`
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore3.1 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:dotnetcore3.1 test::test.Function::FunctionHandler '{"some": "event"}'
```
13 changes: 13 additions & 0 deletions examples/dotnetcore3.1/test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</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>
17 changes: 17 additions & 0 deletions examples/dotnetcore3.1/test.sln
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
Loading

0 comments on commit ab9d48d

Please sign in to comment.