forked from lambci/docker-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
292 additions
and
53 deletions.
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
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_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; | ||
} | ||
} | ||
} |
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": "netcoreapp3.1", | ||
"function-runtime": "dotnetcore3.1", | ||
"function-memory-size": 3008, | ||
"function-timeout": 60, | ||
"function-handler": "dump_dotnetcore31::dump_dotnetcore31.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>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> |
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
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,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"] |
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/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"] |
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-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!"; | ||
} | ||
} | ||
} |
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 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"}' | ||
``` |
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>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> |
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 |
Oops, something went wrong.