commit 998266798a83cb5d44d46d1bda4c246542083aba Author: Alex Hyett Date: Mon Dec 10 12:49:31 2018 +0000 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2920b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# .NET compiled files +**/bin +**/obj \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..0b095c1 --- /dev/null +++ b/Readme.md @@ -0,0 +1,40 @@ +# AWS Lambda .Net Core Console Example + +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 to get started from the command line: + +Once you have edited your template and code you can deploy your application using the [Amazon.Lambda.Tools Global Tool](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) from the command line. + +Install Amazon.Lambda.Tools Global Tools if not already installed. + +``` + dotnet tool install -g Amazon.Lambda.Tools +``` + +If already installed check if new version is available. + +``` + dotnet tool update -g Amazon.Lambda.Tools +``` + +Execute unit tests + +``` + cd "test/lambda-dotnet-console.Tests" + dotnet test +``` + +Deploy function to AWS Lambda + +``` + cd "src/lambda-dotnet-console" + dotnet lambda deploy-function +``` diff --git a/src/lambda-dotnet-console/Function.cs b/src/lambda-dotnet-console/Function.cs new file mode 100644 index 0000000..5f5699d --- /dev/null +++ b/src/lambda-dotnet-console/Function.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +using Amazon.Lambda.Core; + +// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. +[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] + +namespace lambda_dotnet_console +{ + public class Function + { + + /// + /// A simple function that takes a string and does a ToUpper + /// + /// + /// + /// + public string FunctionHandler(string input, ILambdaContext context) + { + return input?.ToUpper(); + } + } +} diff --git a/src/lambda-dotnet-console/aws-lambda-tools-defaults.json b/src/lambda-dotnet-console/aws-lambda-tools-defaults.json new file mode 100644 index 0000000..184387a --- /dev/null +++ b/src/lambda-dotnet-console/aws-lambda-tools-defaults.json @@ -0,0 +1,19 @@ +{ + "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" : "eu-west-1", + "configuration" : "Release", + "framework" : "netcoreapp2.1", + "function-runtime":"dotnetcore2.1", + "function-memory-size" : 256, + "function-timeout" : 30, + "function-handler" : "lambda-dotnet-console::lambda_dotnet_console.Function::FunctionHandler" +} diff --git a/src/lambda-dotnet-console/lambda-dotnet-console.csproj b/src/lambda-dotnet-console/lambda-dotnet-console.csproj new file mode 100644 index 0000000..11a3d67 --- /dev/null +++ b/src/lambda-dotnet-console/lambda-dotnet-console.csproj @@ -0,0 +1,14 @@ + + + + netcoreapp2.1 + true + Lambda + + + + + + + + diff --git a/test/lambda-dotnet-console.Tests/FunctionTest.cs b/test/lambda-dotnet-console.Tests/FunctionTest.cs new file mode 100644 index 0000000..169ff3e --- /dev/null +++ b/test/lambda-dotnet-console.Tests/FunctionTest.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +using Xunit; +using Amazon.Lambda.Core; +using Amazon.Lambda.TestUtilities; + +using lambda_dotnet_console; + +namespace lambda_dotnet_console.Tests +{ + public class FunctionTest + { + [Fact] + public void TestToUpperFunction() + { + + // Invoke the lambda function and confirm the string was upper cased. + var function = new Function(); + var context = new TestLambdaContext(); + var upperCase = function.FunctionHandler("hello world", context); + + Assert.Equal("HELLO WORLD", upperCase); + } + } +} diff --git a/test/lambda-dotnet-console.Tests/lambda-dotnet-console.Tests.csproj b/test/lambda-dotnet-console.Tests/lambda-dotnet-console.Tests.csproj new file mode 100644 index 0000000..c43cfe0 --- /dev/null +++ b/test/lambda-dotnet-console.Tests/lambda-dotnet-console.Tests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + + +