Commit b3640611 authored by Jason Farrell's avatar Jason Farrell

Application Commit

parent 905c3c36
......@@ -215,3 +215,5 @@ FakesAssemblies/
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
.vscode/
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Amazon.KinesisFirehose;
using Amazon.KinesisFirehose.Model;
using Amazon.Lambda.Core;
using Newtonsoft.Json;
// 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 StockTransactionApi
{
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 async Task<HttpResponseMessage> PostHandler(StockTransaction transaction, ILambdaContext context)
{
var rawContents = JsonConvert.SerializeObject(transaction);
using (var client = new AmazonKinesisFirehoseClient())
{
using (var memStream = new MemoryStream())
{
using (var writer = new StreamWriter(memStream))
{
writer.Write(rawContents);
}
await client.PutRecordAsync("input_transactions", new Record() { Data = memStream });
}
}
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
}
# 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 "BlueprintBaseName"
dotnet restore
```
Execute unit tests
```
cd "BlueprintBaseName/test/BlueprintBaseName.Tests"
dotnet test
```
Deploy function to AWS Lambda
```
cd "BlueprintBaseName/src/BlueprintBaseName"
dotnet lambda deploy-function
```
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace StockTransactionApi
{
public class StockTransaction
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("symbol")]
public string Symbol { get; set; }
[JsonProperty("price")]
public decimal Price { get; set; }
[JsonProperty("share_delta")]
public int ShareDelta { get; set; }
[JsonProperty("user")]
public int UserId { get; set; }
public override string ToString()
{
return $"{Symbol} - {Price}";
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0"/>
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.1.0"/>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2"/>
<PackageReference Include="AWSSDK.KinesisFirehose" Version="3.3.5.3"/>
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.1.3"/>
</ItemGroup>
</Project>
\ No newline at end of file
{
"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-1",
"configuration" : "Release",
"framework" : "netcoreapp2.0",
"function-runtime":"dotnetcore2.0",
"function-memory-size" : 256,
"function-timeout" : 30,
"function-handler" : "StockTransactionApi::StockTransactionApi.Function::PostHandler"
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Amazon.Lambda.Core;
using Amazon.Lambda.TestUtilities;
using StockTransactionApi;
namespace StockTransactionApi.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);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</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\StockTransactionApi\StockTransactionApi.csproj" />
</ItemGroup>
</Project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment