From ac9b8423dc27d8a9e4e115d8e8c4077336c209db Mon Sep 17 00:00:00 2001 From: Stephen Liedig Date: Wed, 5 Dec 2018 23:02:30 +0800 Subject: [PATCH] fix: Update to .NET Core init template (#705) Removed Item Group to include DotNetCliToolReference in project file in favor of .NET Core Global Tools for AWS. Updated packages Amazon.Lambda.APIGatewayEvents and Amazon.Lambda.Serialization.Json to latest versions. --- .../{{cookiecutter.project_name}}/README.md | 31 +++++++++++-- .../src/HelloWorld/HelloWorld.csproj | 10 ++--- .../src/HelloWorld/Readme.md | 45 ------------------- .../HelloWorld/aws-lambda-tools-defaults.json | 21 --------- 4 files changed, 30 insertions(+), 77 deletions(-) delete mode 100644 samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/Readme.md delete mode 100644 samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/aws-lambda-tools-defaults.json diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/README.md b/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/README.md index e20b3d785e..fdf398c822 100644 --- a/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/README.md +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/README.md @@ -6,8 +6,17 @@ This is a sample template for {{ cookiecutter.project_name }} * AWS CLI already configured with Administrator permission * [Docker installed](https://www.docker.com/community-edition) -* [SAM Local installed](https://github.com/awslabs/aws-sam-cli) -* [DotNet Core installed](https://www.microsoft.com/net/download) +* [SAM CLI installed](https://github.com/awslabs/aws-sam-cli) +* [.NET Core installed](https://www.microsoft.com/net/download) + +Please see the [currently supported patch of each major version of .NET Core](https://github.com/aws/aws-lambda-dotnet#version-status) to ensure your functions are compatible with the AWS Lambda runtime. + +## Recommended Tools for Visual Studio / Visual Studio Code Users + +* [AWS Toolkit for Visual Studio](https://aws.amazon.com/visualstudio/) +* [AWS Extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli) which are AWS extensions to the .NET CLI focused on building .NET Core and ASP.NET Core applications and deploying them to AWS services including Amazon Elastic Container Service, AWS Elastic Beanstalk and AWS Lambda. + +> **Note: this project uses [Cake Build](https://cakebuild.net/) for build, test and packaging requirements. You do not need to have the [AWS Extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli) installed, but are free to do so if you which to use them. Version 3 of the Amazon.Lambda.Tools does require .NET Core 2.1 for installation, but can be used to deploy older versions of .NET Core.** ## Setup process @@ -43,7 +52,6 @@ Events: Method: get ``` - If the previous command run successfully you should now be able to hit the following local endpoint to invoke your function `http://localhost:3000/hello` ## Packaging and deployment @@ -92,6 +100,7 @@ aws cloudformation describe-stacks \ --stack-name {{ cookiecutter.project_name.lower().replace(' ', '-') }} \ --query 'Stacks[].Outputs' ``` + ## Testing For testing our code, we use XUnit and you can use `dotnet test` to run tests defined under `test/` @@ -118,7 +127,7 @@ build.ps1 --target=Test ## AWS CLI commands -AWS CLI commands to package, deploy and describe outputs defined within the cloudformation stack: +AWS CLI commands to package, deploy and describe outputs defined within the AWS CloudFormation stack: ```bash aws cloudformation package \ @@ -136,6 +145,20 @@ aws cloudformation describe-stacks \ --stack-name {{ cookiecutter.project_name.lower().replace(' ', '-') }} --query 'Stacks[].Outputs' ``` +## Next Steps + +Create your own .NET Core solution template to use with SAM CLI. [Cookiecutter for AWS SAM and .NET](https://github.com/aws-samples/cookiecutter-aws-sam-dotnet) provides you with a sample implementation how to use cookiecutter templating library to standardise how you initialise your Serverless projects. + +``` bash + sam init --location gh:aws-samples/cookiecutter-aws-sam-dotnet +``` + +For more information and examples of how to use `sam init` run + +``` bash +sam init --help +``` + ## Bringing to the next level Here are a few ideas that you can use to get more acquainted as to how this overall process works: diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/HelloWorld.csproj b/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/HelloWorld.csproj index 5555ae3fb3..bd6e37009c 100644 --- a/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/HelloWorld.csproj +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/HelloWorld.csproj @@ -11,14 +11,10 @@ - - + + - - - - - + diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/Readme.md b/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/Readme.md deleted file mode 100644 index 5badecf662..0000000000 --- a/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/Readme.md +++ /dev/null @@ -1,45 +0,0 @@ -# AWS Lambda Empty Function Project - -This starter project consists of: -* Function.cs - class file containing a class with a single function handler method -* aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS - -You may also have a test project depending on the options selected. - -The generated function handler is a simple method accepting a string argument that returns the uppercase equivalent of the input string. Replace the body of this method, and parameters, to suit your needs. - -## Here are some steps to follow from Visual Studio: - -To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. - -To view your deployed function open its Function View window by double-clicking the function name shown beneath the AWS Lambda node in the AWS Explorer tree. - -To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. - -To configure event sources for your deployed function, for example to have your function invoked when an object is created in an Amazon S3 bucket, use the Event Sources tab in the opened Function View window. - -To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. - -To view execution logs of invocations of your function use the Logs tab in the opened Function View window. - -## Here are some steps to follow to get started from the command line: - -Once you have edited your function you can use the following command lines to build, test and deploy your function to AWS Lambda from the command line (these examples assume the project name is *EmptyFunction*): - -Restore dependencies -``` - cd "{{cookiecutter.project_name}}" - dotnet restore -``` - -Execute unit tests -``` - cd "{{cookiecutter.project_name}}/test/{{cookiecutter.project_name}}.Tests" - dotnet test -``` - -Deploy function to AWS Lambda -``` - cd "{{cookiecutter.project_name}}/src/{{cookiecutter.project_name}}" - dotnet lambda deploy-function -``` diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/aws-lambda-tools-defaults.json b/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/aws-lambda-tools-defaults.json deleted file mode 100644 index 6abea00518..0000000000 --- a/samcli/local/init/templates/cookiecutter-aws-sam-hello-dotnet/{{cookiecutter.project_name}}/src/HelloWorld/aws-lambda-tools-defaults.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "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": "default", - "region": "us-east-2", - "configuration": "Release", - {%- if cookiecutter.runtime == 'dotnetcore2.0' %} - "framework": "netcoreapp2.0", - "function-runtime": "{{ cookiecutter.runtime }}", - {%- elif cookiecutter.runtime == 'dotnetcore2.1' or cookiecutter.runtime == 'dotnet' %} - "function-runtime": "dotnetcore2.1", - "framework": "netcoreapp2.1", - {%- endif %} - "function-memory-size": 256, - "function-timeout": 30, - "function-handler": "HelloWorld::HelloWorld.Function::FunctionHandler" -}