Skip to content

Commit

Permalink
fix: dotnet template's build issue (#445)
Browse files Browse the repository at this point in the history
* fix: dotnet template's build issue

* fix cloud watch template

* fix unit tests

* fix other places

* update S3 event

* fix scratch lambda

* fix sns template

* fix sqs

* update serverless api

* update unit tests

* update cw-event project name

* fixed cw event source

* fix S3 template

* sns changes

* fix sqs event template

* fix cw event template

* fix cw event readme
  • Loading branch information
mndeveci authored Aug 11, 2023
1 parent 8ed83e0 commit d73ceed
Show file tree
Hide file tree
Showing 51 changed files with 104 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace {{cookiecutter.project_name}};
namespace CloudWatchEventSource;

public class Function
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ If already installed check if new version is available.

Execute unit tests
```
cd "{{cookiecutter.project_name}}/test/{{cookiecutter.project_name}}.Tests"
cd "{{cookiecutter.project_name}}/test/CloudWatchEventSource.Tests"
dotnet test
```

Deploy function to AWS Lambda
```
cd "{{cookiecutter.project_name}}/src/{{cookiecutter.project_name}}"
dotnet lambda deploy-function
cd "{{cookiecutter.project_name}}"
sam deploy
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"function-runtime": "dotnet6",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "{{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler"
"function-handler": "CloudWatchEventSource::CloudWatchEventSource.Function::FunctionHandler"
}
4 changes: 2 additions & 2 deletions dotnet6/cw-event/{{cookiecutter.project_name}}/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Description: A Lambda function that logs the payload of messages from a scheduled CloudWatch Event
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/CloudWatchEventSource/
Handler: CloudWatchEventSource::CloudWatchEventSource.Function::FunctionHandler
Runtime: dotnet6
{%- if cookiecutter.architectures.value != [ ]%}
Architectures:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\{{cookiecutter.project_name}}\{{cookiecutter.project_name}}.csproj" />
<ProjectReference Include="..\..\src\CloudWatchEventSource\CloudWatchEventSource.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Amazon.Lambda.TestUtilities;
using Amazon.Lambda.CloudWatchEvents;

namespace {{cookiecutter.project_name}}.Tests;
namespace CloudWatchEventSource.Tests;

public class FunctionTest
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet6/s3/{{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ Resources:
S3JsonLoggerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/S3EventSource/
Handler: S3EventSource::S3EventSource.Function::FunctionHandler
Runtime: dotnet6
MemorySize: 256
DeadLetterQueue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace {{cookiecutter.project_name}}
namespace S3EventSource
{
public class Function
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet6/s3/{{cookiecutter.project_name}}/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Resources:
# More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/S3EventSource/
Handler: S3EventSource::S3EventSource.Function::FunctionHandler
Runtime: dotnet6
MemorySize: 256
Policies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
using Amazon.S3.Model;
using Amazon.S3.Util;

using {{cookiecutter.project_name}};
using S3EventSource;

namespace {{cookiecutter.project_name}}.Tests
namespace S3EventSource.Tests
{
public class FunctionTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\{{cookiecutter.project_name}}\{{cookiecutter.project_name}}.csproj" />
<ProjectReference Include="..\..\src\S3EventSource\S3EventSource.csproj" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions dotnet6/scratch/{{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Resources:
helloFromLambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/ScratchLambda/
Handler: ScratchLambda::ScratchLambda.Function::FunctionHandler
Runtime: dotnet6
MemorySize: 256
Timeout: 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace {{cookiecutter.project_name}}
namespace ScratchLambda
{
public class Function
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet6/scratch/{{cookiecutter.project_name}}/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Resources:
helloFromLambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/ScratchLambda/
Handler: ScratchLambda::ScratchLambda.Function::FunctionHandler
Runtime: dotnet6
{%- if cookiecutter.architectures.value != [ ]%}
Architectures:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using Amazon.Lambda.Core;
using Amazon.Lambda.TestUtilities;

using {{cookiecutter.project_name}};
using ScratchLambda;

namespace {{cookiecutter.project_name}}.Tests
namespace ScratchLambda.Tests
{
public class FunctionTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\{{cookiecutter.project_name}}\{{cookiecutter.project_name}}.csproj" />
<ProjectReference Include="..\..\src\ScratchLambda\ScratchLambda.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace {{cookiecutter.project_name}};
namespace SNSEventSource;

public class Function
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"Information": [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"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.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile": "",
"region": "",
"configuration": "Release",
"function-runtime": "dotnet6",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "{{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler"
{
"Information": [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"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.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile": "",
"region": "",
"configuration": "Release",
"function-runtime": "dotnet6",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "SNSEventSource::SNSEventSource.Function::FunctionHandler"
}
4 changes: 2 additions & 2 deletions dotnet6/sns/{{cookiecutter.project_name}}/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Description: A Lambda function that logs the payload of messages sent to an associated SNS topic.
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/SNSEventSource/
Handler: SNSEventSource::SNSEventSource.Function::FunctionHandler
Runtime: dotnet6
{%- if cookiecutter.architectures.value != [ ]%}
Architectures:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Amazon.Lambda.TestUtilities;
using Amazon.Lambda.SNSEvents;

namespace {{cookiecutter.project_name}}.Tests;
namespace SNSEventSource.Tests;

public class FunctionTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\{{cookiecutter.project_name}}\{{cookiecutter.project_name}}.csproj" />
<ProjectReference Include="..\..\src\SNSEventSource\SNSEventSource.csproj" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions dotnet6/sqs/{{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Resources:
SQSPayloadLogger:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/SQSEventSource/
Handler: SQSEventSource::SQSEventSource.Function::FunctionHandler
Runtime: dotnet6
MemorySize: 256
DeadLetterQueue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace {{cookiecutter.project_name}}
namespace SQSEventSource
{
public class Function
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet6/sqs/{{cookiecutter.project_name}}/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Resources:
SQSPayloadLogger:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/SQSEventSource/
Handler: SQSEventSource::SQSEventSource.Function::FunctionHandler
Runtime: dotnet6
{%- if cookiecutter.architectures.value != [ ]%}
Architectures:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Amazon.Lambda.TestUtilities;
using Amazon.Lambda.SQSEvents;

using {{cookiecutter.project_name}};
using SQSEventSource;

namespace {{cookiecutter.project_name}}.Tests
namespace SQSEventSource.Tests
{
public class FunctionTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\{{cookiecutter.project_name}}\{{cookiecutter.project_name}}.csproj" />
<ProjectReference Include="..\..\src\SQSEventSource\SQSEventSource.csproj" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions dotnet6/web/{{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Build your application with the `sam build` command.
{{ cookiecutter.project_name }}$ sam build
```

The SAM CLI installs dependencies defined in `src/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}.csproj`, creates a deployment package, and saves it in the `.aws-sam/build` folder.
The SAM CLI installs dependencies defined in `src/ServerlessAPI/ServerlessAPI.csproj`, creates a deployment package, and saves it in the `.aws-sam/build` folder.

Test a single function by invoking it directly with a test event. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the `events` folder in this project.

Expand Down Expand Up @@ -88,8 +88,8 @@ Resources:
NetCodeWebAPIServerless:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/{{cookiecutter.project_name}}/
Handler: {{cookiecutter.project_name}}::{{cookiecutter.project_name}}.Function::FunctionHandler
CodeUri: ./src/ServerlessAPI/
Handler: ServerlessAPI::ServerlessAPI.Function::FunctionHandler
Runtime: dotnet6
MemorySize: 1042
DeadLetterQueue:
Expand Down Expand Up @@ -128,7 +128,7 @@ You can find more information and examples about filtering Lambda function logs
Tests are defined in the `test` folder in this project.

```bash
{{ cookiecutter.project_name }}$ dotnet test test/{{cookiecutter.project_name}}.Tests/{{cookiecutter.project_name}}.Tests.csproj
{{ cookiecutter.project_name }}$ dotnet test test/ServerlessAPI.Tests/ServerlessAPI.Tests.csproj
```

## Cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DEAF7F92-411E-4FE7-823B-C4F5DB41BBF8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{cookiecutter.project_name}}", "src\{{cookiecutter.project_name}}\{{cookiecutter.project_name}}.csproj", "{FC5B185F-DEBF-46D8-B864-9EF757827789}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerlessAPI", "src\ServerlessAPI\ServerlessAPI.csproj", "{FC5B185F-DEBF-46D8-B864-9EF757827789}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{5527D965-E863-4E48-8EC1-713E276D1BBD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{cookiecutter.project_name}}.Tests", "tests\{{cookiecutter.project_name}}.Tests\{{cookiecutter.project_name}}.Tests.csproj", "{923A8DB8-35F2-4671-8BC2-A7BB8B639348}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerlessAPI.Tests", "tests\ServerlessAPI.Tests\ServerlessAPI.Tests.csproj", "{923A8DB8-35F2-4671-8BC2-A7BB8B639348}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Amazon.DynamoDBv2.DataModel;
using Microsoft.AspNetCore.Mvc;
using {{cookiecutter.project_name}}.Entities;
using {{cookiecutter.project_name}}.Repositories;
using ServerlessAPI.Entities;
using ServerlessAPI.Repositories;

namespace {{cookiecutter.project_name}}.Controllers;
namespace ServerlessAPI.Controllers;

[Route("api/[controller]")]
[Produces("application/json")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Amazon.DynamoDBv2.DataModel;

namespace {{cookiecutter.project_name}}.Entities;
namespace ServerlessAPI.Entities;

// <summary>
/// Map the Book Class to DynamoDb Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Amazon;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
using {{cookiecutter.project_name}}.Repositories;
using ServerlessAPI.Repositories;


var builder = WebApplication.CreateBuilder(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ If already installed check if new version is available.

Deploy application
```
cd "{{cookiecutter.project_name}}/src/{{cookiecutter.project_name}}"
dotnet lambda deploy-serverless
cd "{{cookiecutter.project_name}}/src/ServerlessAPI"
sam deploy
```
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
using {{cookiecutter.project_name}}.Entities;
using ServerlessAPI.Entities;

namespace {{cookiecutter.project_name}}.Repositories
namespace ServerlessAPI.Repositories
{


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using {{cookiecutter.project_name}}.Entities;
using ServerlessAPI.Entities;

namespace {{cookiecutter.project_name}}.Repositories
namespace ServerlessAPI.Repositories
{
/// <summary>
/// Sample DynamoDB Table book CRUD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="{{cookiecutter.project_name}}.Tests" />
<InternalsVisibleTo Include="ServerlessAPI.Tests" />
</ItemGroup>

</Project>
Loading

0 comments on commit d73ceed

Please sign in to comment.