Skip to content

Commit 172bd21

Browse files
authored
Merge branch 'master' into feature/add-dynamo-to-elasticsearch-example
2 parents 2256d0d + 8cf6dbf commit 172bd21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+4195
-507
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ tmp
2323
*.swp
2424
*.swo
2525
vendor
26+
./bin/Debug/netcoreapp2.1/
27+
./bin/release/netcoreapp2.1/

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ serverless install -u https://github.com/serverless/examples/tree/master/folder-
4343
| Example | Runtime |
4444
|:--------------------------- |:-----|
4545
| [Aws Dynamo Stream To Es](https://github.com/serverless/examples/tree/master/aws-golang-dynamo-stream-to-es) <br/> This example deploys a Dynamo DB Table, an ElasticSearch Node, and a lambda triggered off of a Dynamo Stream which updates an elasticsearch index with the data from the Dynamo Table | golang |
46+
| [Aws Dotnet Rest Api With Dynamodb](https://github.com/serverless/examples/tree/master/aws-dotnet-rest-api-with-dynamodb/src/DotNetServerless.Lambda) <br/> Reading/Writing operations using .NET Core and DynamoDB | dotnet |
47+
| [Aws Lambda Layer](https://github.com/serverless/examples/tree/master/aws-ffmpeg-layer) | nodeJS |
4648
| [Aws Golang Simple Http Endpoint](https://github.com/serverless/examples/tree/master/aws-golang-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with golang | golang |
4749
| [Aws Golang Stream Kinesis To Elasticsearch](https://github.com/serverless/examples/tree/master/aws-golang-stream-kinesis-to-elasticsearch) <br/> Pull data from AWS Kinesis streams and forward to elasticsearch | golang |
4850
| [Aws Alexa Skill](https://github.com/serverless/examples/tree/master/aws-node-alexa-skill) <br/> This example demonstrates how to use an AWS Lambdas for your custom Alexa skill. | nodeJS |
@@ -90,6 +92,7 @@ serverless install -u https://github.com/serverless/examples/tree/master/folder-
9092
| [Azure Nodejs](https://github.com/serverless/examples/tree/master/azure-node-line-bot) <br/> Azure Functions sample for the Serverless framework | nodeJS |
9193
| [Azure Node Simple Http Endpoint](https://github.com/serverless/examples/tree/master/azure-node-simple-http-endpoint) <br/> An example of making http endpoints with the Azure Functions Serverless Framework plugin | nodeJS |
9294
| [Azure Nodejs](https://github.com/serverless/examples/tree/master/azure-node-telegram-bot) <br/> Azure Functions sample for the Serverless framework | nodeJS |
95+
| [Google Golang Simple Http Endpoint](https://github.com/serverless/examples/tree/master/google-golang-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with golang | golang |
9396
| [Google Node Simple Http Endpoint](https://github.com/serverless/examples/tree/master/google-node-simple-http-endpoint) <br/> An example of making http endpoints with the Google Cloud Functions Serverless Framework plugin. | nodeJS |
9497
| [Gcp Node Typescript Simple](https://github.com/serverless/examples/tree/master/google-node-typescript-http-endpoint) <br/> Simple HTTP example for GCP functions by Serverless framework with Typescript | nodeJS |
9598
| [Google Python Simple Http Endpoint](https://github.com/serverless/examples/tree/master/google-python-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with python | python |

Diff for: aws-dotnet-rest-api-with-dynamodb/.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
node_modules
1+
git node_modules
22
.serverless
33
*.swp
44
*.*~
@@ -33,4 +33,6 @@ msbuild.err
3333
msbuild.wrn
3434

3535
# Visual Studio 2015
36-
.vs/
36+
.vs/
37+
38+
env.configs.yml
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E45346EE-74B7-4F5B-943C-FEFDE57124D0}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{DBC29D13-84FE-4A90-B785-E325BDD494A8}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetServerless.Lambda", "src\DotNetServerless.Lambda\DotNetServerless.Lambda.csproj", "{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetServerless.Tests", "tests\DotNetServerless.Tests\DotNetServerless.Tests.csproj", "{045DC8E9-8CA6-4B76-9C4A-781AB9589700}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetServerless.Application", "src\DotNetServerless.Application\DotNetServerless.Application.csproj", "{8F0BB856-4F83-4898-ACC7-68D672386742}"
15+
EndProject
16+
Global
17+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18+
Debug|Any CPU = Debug|Any CPU
19+
Debug|x64 = Debug|x64
20+
Debug|x86 = Debug|x86
21+
Release|Any CPU = Release|Any CPU
22+
Release|x64 = Release|x64
23+
Release|x86 = Release|x86
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
29+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Debug|x64.ActiveCfg = Debug|Any CPU
32+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Debug|x64.Build.0 = Debug|Any CPU
33+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Debug|x86.ActiveCfg = Debug|Any CPU
34+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Debug|x86.Build.0 = Debug|Any CPU
35+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Release|x64.ActiveCfg = Release|Any CPU
38+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Release|x64.Build.0 = Release|Any CPU
39+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Release|x86.ActiveCfg = Release|Any CPU
40+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F}.Release|x86.Build.0 = Release|Any CPU
41+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Debug|x64.ActiveCfg = Debug|Any CPU
44+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Debug|x64.Build.0 = Debug|Any CPU
45+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Debug|x86.ActiveCfg = Debug|Any CPU
46+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Debug|x86.Build.0 = Debug|Any CPU
47+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Release|x64.ActiveCfg = Release|Any CPU
50+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Release|x64.Build.0 = Release|Any CPU
51+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Release|x86.ActiveCfg = Release|Any CPU
52+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700}.Release|x86.Build.0 = Release|Any CPU
53+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Debug|x64.ActiveCfg = Debug|Any CPU
56+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Debug|x64.Build.0 = Debug|Any CPU
57+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Debug|x86.ActiveCfg = Debug|Any CPU
58+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Debug|x86.Build.0 = Debug|Any CPU
59+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Release|x64.ActiveCfg = Release|Any CPU
62+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Release|x64.Build.0 = Release|Any CPU
63+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Release|x86.ActiveCfg = Release|Any CPU
64+
{8F0BB856-4F83-4898-ACC7-68D672386742}.Release|x86.Build.0 = Release|Any CPU
65+
EndGlobalSection
66+
GlobalSection(NestedProjects) = preSolution
67+
{9A74B45A-50B6-44C8-A2D7-F7778A61F18F} = {E45346EE-74B7-4F5B-943C-FEFDE57124D0}
68+
{045DC8E9-8CA6-4B76-9C4A-781AB9589700} = {DBC29D13-84FE-4A90-B785-E325BDD494A8}
69+
{8F0BB856-4F83-4898-ACC7-68D672386742} = {E45346EE-74B7-4F5B-943C-FEFDE57124D0}
70+
EndGlobalSection
71+
EndGlobal

Diff for: aws-dotnet-rest-api-with-dynamodb/README.MD

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
# DotNetServerless
3+
4+
The following AWS lambda is built in .NET Core 2.1
5+
6+
7+
## Configure lambda
8+
9+
It is possible configure the lambda by editing the `env.config.yml` file:
10+
11+
```
12+
feature: <feature_name>
13+
version: 1.0.0.0
14+
region: <aws_region>
15+
environment: <environment>
16+
accountId: <aws_account_id>
17+
dynamoTable: <dynamo_table_name>
18+
```
19+
20+
## Run
21+
22+
The project contains a `package.json` file with the following commands:
23+
24+
```
25+
npm run tests
26+
```
27+
28+
```
29+
npm run build
30+
```
31+
32+
```
33+
npm run deploy
34+
```

Diff for: aws-dotnet-rest-api-with-dynamodb/TodoLambda.sln

-54
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
</PropertyGroup>
6-
7-
<ItemGroup>
8-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.14.12" />
9-
<PackageReference Include="MediatR" Version="5.1.0" />
10-
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="5.1.0" />
11-
<PackageReference Include="AWSSDK.Core" Version="3.3.29.3" />
12-
<PackageReference Include="AWSSDK.Core" Version="3.3.29.3" />
13-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.1.0" />
14-
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
15-
</ItemGroup>
16-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.14.12" />
9+
<PackageReference Include="MediatR" Version="5.1.0" />
10+
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="5.1.0" />
11+
<PackageReference Include="AWSSDK.Core" Version="3.3.29.3" />
12+
<PackageReference Include="AWSSDK.Core" Version="3.3.29.3" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.1.0" />
14+
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
15+
</ItemGroup>
16+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Amazon.DynamoDBv2.DataModel;
2+
3+
namespace DotNetServerless.Application.Entities
4+
{
5+
public class Item
6+
{
7+
[DynamoDBHashKey]
8+
public string Id { get; set; }
9+
[DynamoDBRangeKey]
10+
public string Code { get; set; }
11+
[DynamoDBProperty]
12+
public string Description { get; set; }
13+
[DynamoDBProperty]
14+
public bool IsChecked { get; set; }
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using DotNetServerless.Application.Entities;
5+
using DotNetServerless.Application.Infrastructure.Repositories;
6+
using DotNetServerless.Application.Requests;
7+
using MediatR;
8+
9+
namespace DotNetServerless.Application.Handlers
10+
{
11+
public class CreateItemHandler : IRequestHandler<CreateItemRequest, Item>
12+
{
13+
private readonly IItemRepository _itemRepository;
14+
15+
public CreateItemHandler(IItemRepository itemRepository)
16+
{
17+
_itemRepository = itemRepository;
18+
}
19+
20+
public async Task<Item> Handle(CreateItemRequest request, CancellationToken cancellationToken)
21+
{
22+
var item = request.Map();
23+
item.Id = Guid.NewGuid().ToString();
24+
25+
await _itemRepository.Save(item, cancellationToken);
26+
27+
return item;
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Linq;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using DotNetServerless.Application.Entities;
5+
using DotNetServerless.Application.Infrastructure.Repositories;
6+
using DotNetServerless.Application.Requests;
7+
using MediatR;
8+
9+
namespace DotNetServerless.Application.Handlers
10+
{
11+
public class GetItemHandler : IRequestHandler<GetItemRequest, Item>
12+
{
13+
private readonly IItemRepository _itemRepository;
14+
15+
public GetItemHandler(IItemRepository itemRepository)
16+
{
17+
_itemRepository = itemRepository;
18+
}
19+
20+
21+
public async Task<Item> Handle(GetItemRequest request, CancellationToken cancellationToken)
22+
{
23+
var result = await _itemRepository.GetById<Item>(request.Id.ToString(), cancellationToken);
24+
return result.FirstOrDefault();
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
using DotNetServerless.Application.Entities;
4+
using DotNetServerless.Application.Infrastructure.Repositories;
5+
using DotNetServerless.Application.Requests;
6+
using MediatR;
7+
8+
namespace DotNetServerless.Application.Handlers
9+
{
10+
public class UpdateItemHandler : IRequestHandler<UpdateItemRequest, Item>
11+
{
12+
private readonly IItemRepository _itemRepository;
13+
14+
public UpdateItemHandler(IItemRepository itemRepository)
15+
{
16+
_itemRepository = itemRepository;
17+
}
18+
19+
public async Task<Item> Handle(UpdateItemRequest request, CancellationToken cancellationToken)
20+
{
21+
var item = request.Map();
22+
await _itemRepository.Save(item, cancellationToken);
23+
return item;
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using Amazon.Runtime;
3+
using DotNetServerless.Application.Infrastructure.Configs;
4+
5+
namespace DotNetServerless.Application.Infrastructure
6+
{
7+
public interface IAwsClientFactory<out T>
8+
{
9+
T GetAwsClient();
10+
}
11+
12+
public class AwsClientFactory<T> : IAwsClientFactory<T> where T : AmazonServiceClient, new()
13+
{
14+
private readonly IAwsBasicConfiguration _awsBasicConfiguration;
15+
16+
public AwsClientFactory(AwsBasicConfiguration awsBasicConfiguration)
17+
{
18+
_awsBasicConfiguration = awsBasicConfiguration;
19+
}
20+
21+
public T GetAwsClient()
22+
{
23+
return string.IsNullOrEmpty(_awsBasicConfiguration.AccessKey) ||
24+
string.IsNullOrEmpty(_awsBasicConfiguration.SecretKey)
25+
? (T) Activator.CreateInstance(typeof(T))
26+
: (T) Activator.CreateInstance(typeof(T), _awsBasicConfiguration.GetAwsCredentials(),
27+
_awsBasicConfiguration.RegionEndpoint);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)