Skip to content

Commit 5573bdb

Browse files
author
Roman Lumetsberger
committed
refactoring of dumpdonet2
1 parent 095cc3a commit 5573bdb

6 files changed

Lines changed: 59 additions & 36 deletions

File tree

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
base/diff
33
*.pyc
4+
*.vs
45
.gradle
56
java8/run/lambda-runtime-mock/target
67
base/dump-java8/target
@@ -13,3 +14,11 @@ examples/go1.x/handler
1314
examples/go1.x/vendor
1415
dotnetcore2.0/run/bin
1516
dotnetcore2.0/run/obj
17+
dotnetcore2.0/run/MockBootstraps/bin
18+
dotnetcore2.0/run/MockBootstraps/obj
19+
java8/run/lambda-runtime-mock/target
20+
base/dump-dotnet2/bin
21+
base/dump-dotnet2/obj
22+
examples/dotnetcore2.0/test/bin
23+
examples/dotnetcore2.0/test/obj
24+
examples/dotnetcore2.0/test/pub

base/dump-dotnet2/Function.cs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System;
32
using System.Diagnostics;
4-
using System.IO;
5-
using System.Linq;
63
using System.Threading.Tasks;
74

85
using Amazon.Lambda.Core;
9-
using Amazon.Lambda.S3Events;
106
using Amazon.S3;
11-
using Amazon.S3.Util;
127

138
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
149
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
@@ -41,35 +36,27 @@ public static string Bash(this string cmd)
4136

4237
public class Function
4338
{
44-
IAmazonS3 S3Client { get; set; }
39+
IAmazonS3 S3Client { get; }
4540

4641
/// <summary>
4742
/// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment
4843
/// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the
4944
/// region the Lambda function is executed in.
5045
/// </summary>
51-
public Function()
52-
{
53-
S3Client = new AmazonS3Client();
54-
}
46+
public Function() => S3Client = new AmazonS3Client();
5547

5648
/// <summary>
5749
/// Constructs an instance with a preconfigured S3 client. This can be used for testing the outside of the Lambda environment.
5850
/// </summary>
5951
/// <param name="s3Client"></param>
60-
public Function(IAmazonS3 s3Client)
61-
{
62-
this.S3Client = s3Client;
63-
}
64-
52+
public Function(IAmazonS3 s3Client) => S3Client = s3Client;
53+
6554
/// <summary>
66-
/// This method is called for every Lambda invocation. This method takes in an S3 event object and can be used
67-
/// to respond to S3 notifications.
55+
/// Lambda function to dump the container directories /var/lang
56+
/// and /var/runtime and upload the resulting archive to S3
6857
/// </summary>
69-
/// <param name="evnt"></param>
70-
/// <param name="context"></param>
7158
/// <returns></returns>
72-
public async Task<string> FunctionHandler(Stream stream)
59+
public async Task<string> FunctionHandler()
7360
{
7461
var environment = Environment.GetEnvironmentVariables();
7562
foreach(var env in environment.Keys){
@@ -79,7 +66,7 @@ public async Task<string> FunctionHandler(Stream stream)
7966
string filename = "dotnet2.tgz";
8067
string cmd = $"tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read /var/runtime /var/lang";
8168

82-
var output = cmd.Bash();
69+
cmd.Bash();
8370

8471
Console.WriteLine("Zipping done! Uploading...");
8572
await S3Client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest{

base/dump-dotnet2/Readme.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AWS Lambda Dump Runtime Project
2-
This functions dumps the runtime and uplaods it to s3.
2+
This functions dumps the runtime and uploads it to s3.
33

44

55
## Here are some steps to follow from Visual Studio:
@@ -20,12 +20,15 @@ To view execution logs of invocations of your function use the Logs tab in the o
2020

2121
Restore dependencies
2222
```
23-
cd "dumpdotnet2"
2423
dotnet restore
2524
```
2625

2726
Deploy function to AWS Lambda
2827
```
29-
cd "dumpdotnet2/src/dumpdotnet2"
30-
dotnet lambda deploy-function
28+
dotnet lambda deploy-function DumpDotnet2
3129
```
30+
31+
Invoke `DumpDotnet2`
32+
```
33+
dotnet lambda invoke-function DumpDotnet2
34+
```
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Information" : [
2+
"Information": [
33
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
44
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
55

@@ -8,12 +8,11 @@
88
"All the command line options for the Lambda command can be specified in this file."
99
],
1010

11-
"profile":"",
12-
"region" : "",
13-
"configuration" : "Release",
14-
"framework" : "netcoreapp2.0",
15-
"function-runtime":"dotnetcore2.0",
16-
"function-memory-size" : 256,
17-
"function-timeout" : 30,
18-
"function-handler" : "dumpdotnet2::dumpdotnet2.Function::FunctionHandler"
11+
"profile": "default",
12+
"configuration": "Release",
13+
"framework": "netcoreapp2.0",
14+
"function-runtime": "dotnetcore2.0",
15+
"function-memory-size": 256,
16+
"function-timeout": 180,
17+
"function-handler": "dumpdotnet2::dump_dotnet.Function::FunctionHandler"
1918
}

base/dump-dotnet2/dumpdotnet2.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.0</TargetFramework>
55
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
6+
<AssemblyName>dumpdotnet2</AssemblyName>
67
</PropertyGroup>
78

89
<ItemGroup>
910
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
1011
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.1.0" />
11-
<PackageReference Include="Amazon.Lambda.S3Events" Version="1.0.2" />
1212
<PackageReference Include="AWSSDK.S3" Version="3.3.16.2" />
1313
</ItemGroup>
1414

base/dump-dotnet2/dumpdotnet2.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27130.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dumpdotnet2", "dumpdotnet2.csproj", "{24B48368-FBF9-41EF-A42E-E9B74AE81507}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{24B48368-FBF9-41EF-A42E-E9B74AE81507}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{24B48368-FBF9-41EF-A42E-E9B74AE81507}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{24B48368-FBF9-41EF-A42E-E9B74AE81507}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{24B48368-FBF9-41EF-A42E-E9B74AE81507}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {20148D06-BAD1-4D77-B1B5-595D0E2CB0BF}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)