Initial Commit
This commit is contained in:
commit
998266798a
7 changed files with 152 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# .NET compiled files
|
||||||
|
**/bin
|
||||||
|
**/obj
|
40
Readme.md
Normal file
40
Readme.md
Normal file
|
@ -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
|
||||||
|
```
|
27
src/lambda-dotnet-console/Function.cs
Normal file
27
src/lambda-dotnet-console/Function.cs
Normal file
|
@ -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
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A simple function that takes a string and does a ToUpper
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string FunctionHandler(string input, ILambdaContext context)
|
||||||
|
{
|
||||||
|
return input?.ToUpper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
src/lambda-dotnet-console/aws-lambda-tools-defaults.json
Normal file
19
src/lambda-dotnet-console/aws-lambda-tools-defaults.json
Normal file
|
@ -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"
|
||||||
|
}
|
14
src/lambda-dotnet-console/lambda-dotnet-console.csproj
Normal file
14
src/lambda-dotnet-console/lambda-dotnet-console.csproj
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||||
|
<AWSProjectType>Lambda</AWSProjectType>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
28
test/lambda-dotnet-console.Tests/FunctionTest.cs
Normal file
28
test/lambda-dotnet-console.Tests/FunctionTest.cs
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
|
||||||
|
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="1.0.0" />
|
||||||
|
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.3.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\lambda-dotnet-console\lambda-dotnet-console.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in a new issue