Skip to content

Commit 5fd7bd3

Browse files
committedDec 3, 2020
v3
1 parent 53e8a58 commit 5fd7bd3

10 files changed

+213
-27
lines changed
 

‎.vs/Assignment4AWSLambda/v16/.suo

4.5 KB
Binary file not shown.

‎AWSService/AWSDynamoService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ public class AWSDynamoService
1818
RegionEndpoint Region = RegionEndpoint.USWest2;
1919
IAmazonDynamoDB dynamoDBClient { get; }
2020
private static AmazonDynamoDBClient client = new AmazonDynamoDBClient();
21-
String tableName = "Images";
21+
String tableName = "MyImage";
2222

2323
public AWSDynamoService(IAmazonDynamoDB dynamoDBClient)
2424
{
2525
this.dynamoDBClient = dynamoDBClient;
2626
CreateTable();
2727
}
2828

29-
public async Task<Image> Create(Image image)
29+
public async Task<MyImage> Create(MyImage image)
3030
{
3131
image.Id = (image.BucketName + image.KeyName);
3232
DynamoDBContext Context = new DynamoDBContext(dynamoDBClient);
33-
await Context.SaveAsync<Image>(image);
33+
await Context.SaveAsync<MyImage>(image);
3434
return image;
3535
}
3636

‎Function.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Amazon.S3;
1515
using Amazon.S3.Model;
1616
using Amazon.DynamoDBv2;
17+
using Assignment4AWSLambda.Model;
1718

1819
//test
1920
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
@@ -52,10 +53,12 @@ public class Function
5253
/// </summary>
5354
public Function()
5455
{
55-
new AWSDynamoService(dynamoDBClient);
56+
this.dynamoDBClient = new AmazonDynamoDBClient();
5657
this.S3Client = new AmazonS3Client();
5758
this.RekognitionClient = new AmazonRekognitionClient();
5859

60+
new AWSDynamoService(dynamoDBClient);
61+
5962
var environmentMinConfidence = System.Environment.GetEnvironmentVariable(MIN_CONFIDENCE_ENVIRONMENT_VARIABLE_NAME);
6063
if(!string.IsNullOrWhiteSpace(environmentMinConfidence))
6164
{
@@ -121,28 +124,42 @@ public async Task FunctionHandler(S3Event input, ILambdaContext context)
121124
});
122125

123126
var tags = new List<Tag>();
127+
var labels = new List<MyLabel>();
124128
foreach(var label in detectResponses.Labels)
125129
{
126130
if(tags.Count < 10)
127131
{
128132
Console.WriteLine($"\tFound Label {label.Name} with confidence {label.Confidence}");
129133
tags.Add(new Tag { Key = label.Name, Value = label.Confidence.ToString() });
134+
labels.Add(new MyLabel { Key = label.Name, Value = label.Confidence.ToString() });
130135
}
131136
else
132137
{
133138
Console.WriteLine($"\tSkipped label {label.Name} with confidence {label.Confidence} because the maximum number of tags has been reached");
134139
}
135140
}
136141

137-
await this.S3Client.PutObjectTaggingAsync(new PutObjectTaggingRequest
142+
143+
MyImage image = new MyImage();
144+
image.BucketName = record.S3.Bucket.Name;
145+
image.KeyName = record.S3.Object.Key;
146+
image.Labels = labels;
147+
image.Processed = false;
148+
image.Metadatainfo = null;
149+
150+
image = new AWSDynamoService(dynamoDBClient).Create(image).Result;
151+
152+
Console.WriteLine($"\tSaved {image.KeyName} with confidence {image.Id}");
153+
154+
/*await this.S3Client.PutObjectTaggingAsync(new PutObjectTaggingRequest
138155
{
139156
BucketName = record.S3.Bucket.Name,
140157
Key = record.S3.Object.Key,
141158
Tagging = new Tagging
142159
{
143160
TagSet = tags
144161
}
145-
});
162+
});*/
146163
}
147164
return;
148165
}

‎Model/Image.cs ‎Model/MyImage.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
namespace Assignment4AWSLambda.Model
55
{
6-
[DynamoDBTable("Images")]
7-
public class Image
6+
[DynamoDBTable("MyImage")]
7+
public class MyImage
88
{
99
[DynamoDBHashKey]
1010
public string Id { get; set; }
@@ -22,6 +22,6 @@ public class Image
2222
public string Metadatainfo { get; set; }
2323

2424
[DynamoDBProperty(AttributeName = "Labels")]
25-
public List<Label> Labels { get; set; }
25+
public List<MyLabel> Labels { get; set; }
2626
}
2727
}

‎Model/Label.cs ‎Model/MyLabel.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Assignment4AWSLambda.Model
44
{
5-
public class Label
5+
public class MyLabel
66
{
77
[DynamoDBProperty]
8-
public string TagName { get; set; }
8+
public string Key { get; set; }
99
[DynamoDBProperty]
10-
public int Value { get; set; }
10+
public string Value { get; set; }
1111
}
1212
}

‎aws-lambda-tools-defaults.json

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
12
{
2-
"Information": [
3-
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
4-
"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.",
5-
"dotnet lambda help",
6-
"All the command line options for the Lambda command can be specified in this file."
7-
],
8-
"profile": "default",
9-
"region": "ca-central-1",
10-
"configuration": "Release",
11-
"framework": "netcoreapp3.1",
12-
"function-runtime": "dotnetcore3.1",
13-
"function-memory-size": 256,
14-
"function-timeout": 30,
15-
"function-handler": "Assignment4AWSLambda::Assignment4AWSLambda.Function::FunctionHandler"
3+
"Information" : [
4+
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
5+
"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.",
6+
"dotnet lambda help",
7+
"All the command line options for the Lambda command can be specified in this file."
8+
],
9+
"profile" : "default",
10+
"region" : "us-west-2",
11+
"configuration" : "Release",
12+
"framework" : "netcoreapp3.1",
13+
"function-runtime" : "dotnetcore3.1",
14+
"function-memory-size" : 256,
15+
"function-timeout" : 30,
16+
"function-handler" : "Assignment4AWSLambda::Assignment4AWSLambda.Function::FunctionHandler",
17+
"function-name" : "Lab4TriggerToDynamo",
18+
"package-type" : "Zip",
19+
"function-role" : "arn:aws:iam::230199793713:role/lambda_exec_Lab4TriggerToDynamo",
20+
"tracing-mode" : "Active",
21+
"environment-variables" : "\"MinConfidence\"=\"90\"",
22+
"image-tag" : "",
23+
"function-description" : ""
1624
}

‎obj/Assignment4AWSLambda.csproj.nuget.dgspec.json

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
},
8585
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.402\\RuntimeIdentifierGraph.json"
8686
}
87+
},
88+
"runtimes": {
89+
"linux-x64": {
90+
"#import": []
91+
}
8792
}
8893
}
8994
}
Binary file not shown.

‎obj/project.assets.json

+156
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,157 @@
151151
"lib/netcoreapp2.0/System.Runtime.CompilerServices.Unsafe.dll": {}
152152
}
153153
}
154+
},
155+
".NETCoreApp,Version=v3.1/linux-x64": {
156+
"Amazon.Lambda.Core/1.2.0": {
157+
"type": "package",
158+
"compile": {
159+
"lib/netstandard2.0/Amazon.Lambda.Core.dll": {}
160+
},
161+
"runtime": {
162+
"lib/netstandard2.0/Amazon.Lambda.Core.dll": {}
163+
}
164+
},
165+
"Amazon.Lambda.S3Events/1.2.0": {
166+
"type": "package",
167+
"dependencies": {
168+
"AWSSDK.S3": "3.5.3.5"
169+
},
170+
"compile": {
171+
"lib/netstandard2.0/Amazon.Lambda.S3Events.dll": {}
172+
},
173+
"runtime": {
174+
"lib/netstandard2.0/Amazon.Lambda.S3Events.dll": {}
175+
}
176+
},
177+
"Amazon.Lambda.Serialization.SystemTextJson/2.1.0": {
178+
"type": "package",
179+
"dependencies": {
180+
"Amazon.Lambda.Core": "1.2.0"
181+
},
182+
"compile": {
183+
"lib/netcoreapp3.1/Amazon.Lambda.Serialization.SystemTextJson.dll": {}
184+
},
185+
"runtime": {
186+
"lib/netcoreapp3.1/Amazon.Lambda.Serialization.SystemTextJson.dll": {}
187+
}
188+
},
189+
"AWSSDK.Core/3.5.1.42": {
190+
"type": "package",
191+
"compile": {
192+
"lib/netcoreapp3.1/AWSSDK.Core.dll": {}
193+
},
194+
"runtime": {
195+
"lib/netcoreapp3.1/AWSSDK.Core.dll": {}
196+
}
197+
},
198+
"AWSSDK.DynamoDBv2/3.5.3": {
199+
"type": "package",
200+
"dependencies": {
201+
"AWSSDK.Core": "[3.5.1.34, 3.6.0)"
202+
},
203+
"compile": {
204+
"lib/netcoreapp3.1/AWSSDK.DynamoDBv2.dll": {}
205+
},
206+
"runtime": {
207+
"lib/netcoreapp3.1/AWSSDK.DynamoDBv2.dll": {}
208+
}
209+
},
210+
"AWSSDK.Rekognition/3.5.2.15": {
211+
"type": "package",
212+
"dependencies": {
213+
"AWSSDK.Core": "[3.5.1.42, 3.6.0)"
214+
},
215+
"compile": {
216+
"lib/netcoreapp3.1/AWSSDK.Rekognition.dll": {}
217+
},
218+
"runtime": {
219+
"lib/netcoreapp3.1/AWSSDK.Rekognition.dll": {}
220+
}
221+
},
222+
"AWSSDK.S3/3.5.5.2": {
223+
"type": "package",
224+
"dependencies": {
225+
"AWSSDK.Core": "[3.5.1.42, 3.6.0)"
226+
},
227+
"compile": {
228+
"lib/netcoreapp3.1/AWSSDK.S3.dll": {}
229+
},
230+
"runtime": {
231+
"lib/netcoreapp3.1/AWSSDK.S3.dll": {}
232+
}
233+
},
234+
"GrapeCity.Documents.Common/3.0.0.415": {
235+
"type": "package",
236+
"compile": {
237+
"lib/netstandard2.0/GrapeCity.Documents.Common.dll": {}
238+
},
239+
"runtime": {
240+
"lib/netstandard2.0/GrapeCity.Documents.Common.dll": {}
241+
},
242+
"resource": {
243+
"lib/netstandard2.0/ja/GrapeCity.Documents.Common.resources.dll": {
244+
"locale": "ja"
245+
}
246+
}
247+
},
248+
"GrapeCity.Documents.Imaging/3.0.0.415": {
249+
"type": "package",
250+
"dependencies": {
251+
"GrapeCity.Documents.Common": "[3.0.0.415]",
252+
"System.Buffers": "4.4.0",
253+
"System.Memory": "4.5.0",
254+
"System.Numerics.Vectors": "4.4.0",
255+
"System.Runtime.CompilerServices.Unsafe": "4.5.0"
256+
},
257+
"compile": {
258+
"lib/netstandard2.0/GrapeCity.Documents.Imaging.dll": {}
259+
},
260+
"runtime": {
261+
"lib/netstandard2.0/GrapeCity.Documents.Imaging.dll": {}
262+
},
263+
"resource": {
264+
"lib/netstandard2.0/ja/GrapeCity.Documents.Imaging.resources.dll": {
265+
"locale": "ja"
266+
}
267+
}
268+
},
269+
"System.Buffers/4.4.0": {
270+
"type": "package",
271+
"compile": {
272+
"ref/netcoreapp2.0/_._": {}
273+
},
274+
"runtime": {
275+
"lib/netcoreapp2.0/_._": {}
276+
}
277+
},
278+
"System.Memory/4.5.0": {
279+
"type": "package",
280+
"compile": {
281+
"ref/netcoreapp2.1/_._": {}
282+
},
283+
"runtime": {
284+
"lib/netcoreapp2.1/_._": {}
285+
}
286+
},
287+
"System.Numerics.Vectors/4.4.0": {
288+
"type": "package",
289+
"compile": {
290+
"ref/netcoreapp2.0/_._": {}
291+
},
292+
"runtime": {
293+
"lib/netcoreapp2.0/_._": {}
294+
}
295+
},
296+
"System.Runtime.CompilerServices.Unsafe/4.5.0": {
297+
"type": "package",
298+
"compile": {
299+
"ref/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": {}
300+
},
301+
"runtime": {
302+
"lib/netcoreapp2.0/System.Runtime.CompilerServices.Unsafe.dll": {}
303+
}
304+
}
154305
}
155306
},
156307
"libraries": {
@@ -578,6 +729,11 @@
578729
},
579730
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.402\\RuntimeIdentifierGraph.json"
580731
}
732+
},
733+
"runtimes": {
734+
"linux-x64": {
735+
"#import": []
736+
}
581737
}
582738
}
583739
}

‎obj/project.nuget.cache

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": 2,
3-
"dgSpecHash": "rZ0W76LK4dZLkljQgQj0clTOkRaYgDFTbNVz35k344T+5u8nVpXqPqzFjOY+w9vXiA3YLWl3+tk6tt2bXH5tIg==",
3+
"dgSpecHash": "NoABLN25MYefQEkGicSukKFAIhIpdLuNv5qSVF2blAMj5DLoaXU44SCtICSa4XMvN2B8CbSj5Jml2LNg5+t3QA==",
44
"success": true,
55
"projectFilePath": "C:\\Comp306_AWSAmazon\\Lab4\\Assignment4AWSLambda\\Assignment4AWSLambda.csproj",
66
"expectedPackageFiles": [

0 commit comments

Comments
 (0)