Skip to content

Instantly share code, notes, and snippets.

@johnjelinek
Last active December 5, 2016 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjelinek/70006aee9615248d30c43d13691f12ca to your computer and use it in GitHub Desktop.
Save johnjelinek/70006aee9615248d30c43d13691f12ca to your computer and use it in GitHub Desktop.
C# Lambda
AWSTemplateFormatVersion: '2010-09-09'
Description: Create a Serverless stack with CloudFormation using Serverless Application Model
Transform: AWS::Serverless-2016-10-31
Resources:
CSharpHelloWorld:
Type: AWS::Serverless::Function
Description: Use a lambda function to print Hello World
Properties:
Handler: csharplambda::CSharpFunction.HelloWorld::Handler
Runtime: dotnetcore1.0
CodeUri: ./bin/Debug/netcoreapp1.0/publish
MemorySize: 128
Timeout: 5
Events:
HelloResource:
Type: Api
Properties:
Path: /hello
Method: get
using Amazon.Lambda.Core;
using Newtonsoft.Json;
namespace CSharpFunction
{
public class Headers
{
[JsonProperty("Content-Type")]
public string ContentType { get; set; }
}
public class Response
{
[JsonProperty("headers")]
public Headers Headers { get; set; }
[JsonProperty("statusCode")]
public int StatusCode { get; set; }
[JsonProperty("body")]
public string Body { get; set; }
}
public class HelloWorld
{
[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
public Response Handler()
{
return new Response
{
Headers = new Headers
{
ContentType = "text/plain"
},
StatusCode = 200,
Body = "Hello World"
};
}
}
}
{
"version": "1.0.0-*",
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Amazon.Lambda.Serialization.Json": "1.0.1",
"Newtonsoft.Json": "9.0.1"
},
"imports": "dnxcore50"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment