aws lambda in c#

Download AWS Lambda in C#

Post on 26-Jan-2017




3 download

Embed Size (px)


  • 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    John Chang ()Technology Evangelist

    January, 2017

    Serverless Development with

    C# and AWS Lambda

  • What to Expect from the Session

    Brief Introduction to AWS Lambda

    Why .NET Core

    New .NET Core Lambda tooling

    Lots of exciting demos!

  • AWS Lambda Crash Course

    Compute part of the AWS serverless architecture

    Zero administration

    Event-driven scaling

    Never pay for idle time

    Upload your code and go

  • Why .NET Core?


    Modularized design

    Low memory usage

    Open Source

    Built and validated for Amazon Linux

    Allow AWS to respond to security issues

    Cross Platform

    Develop on any platform and run on Amazon Linux

  • .NET Core Development

    .NET Core 1.0

    Visual Studio 2015 Update 3

    Visual Studio 2015 Tools (Preview 2)

    Target framework netcoreapp1.0

    Package with .NET Core CLI dotnet publish

    Upload as a zip file

  • Declaring Lambda Functions

    Static or instance methods

    Must have a default constructor for instance methods

    Can take 0 or 1 input parameters

    public void FunctionHandler()

    public void FunctionHandler(S3Event evnt)

    public string FunctionHandler(S3Event evnt, ILambdaContext context)

    Optional ILambdaContext parameter

  • async methods must return a Task or Task

    Declaring Lambda Functions

    public async Task FunctionHandler(T obj, ILambdaContext context)

    public void FunctionHandler(T obj, ILambdaContext context)

    No generic methods

    public async Task FunctionHandler(S3Event evnt, ILambdaContext context) // return void

    public async Task FunctionHandler(S3Event evnt, ILambdaContext context)

  • Invoking Lambda Functions

  • Invoking from AWS Lambda Event Sources

    Function executes in response to events in AWS


    A few of the supported services

    Amazon S3

    Amazon DynamoDB

    Amazon Kinesis


    Scheduled Events

  • Invoking with the AWS SDKs

    Invoke methods using any SDK

    Great for mobile apps

    Manage credentials with Amazon Cognito

    var client = new AmazonLambdaClient(cognitoCredentials, RegionEndpoint.USWest2);

    var request = new InvokeRequest


    FunctionName = "ProcessGameScore",

    Payload = gameStats


    InvokeResponse response = await client.InvokeAsync(request);

  • Invoking from Amazon API Gateway

    Frontend of the AWS Serverless architecture

    Expose Lambda functions as HTTP API

    Manages authentication, versioning, monitoring and


  • Demo Time

  • Demo:

    Responding to AWS Events

  • Recap

    Created a new Lambda project in Visual Studio

    Learned how serialization works

    Learned about the handler format


    Published from Visual Studio

    Configured AWS event source

    Invoked the Lambda function from Visual Studio

  • Demo:Cross Platform: Command Line

  • Yeoman Project Generators

    Project generator ecosystem

    Installable via npm:

    Node.js dependency

    npm install g yo

    AWS Lambda generators

    npm install g generator-aws-lambda-dotnet

    yo aws-lambda-dotnet

  • Recap Cross-Platform Demo

    Created a project with Yeoman

    npm install g yo generator-aws-lambda-dotnet

    yo aws-lambda-dotnet

    Develop with any editor

    Command line deployment with the .NET CLI and

    Amazon.Lambda.Tools NuGet package

    dotnet lambda

    In preview

  • Demo:

    Serverless Application

  • Demo Application Architecture





    RemoveBlog()API Gateway

    AWS Lambda

    Amazon DynamoDB

    AWS CloudFormation Stack

  • Our Serverless Application Deployment

    Visual Studio


    Amazon S3

    AWS CloudFormation

    App bundle




    2: Request stack

    other resources

    Lambda Functions

    other resources

    API Gateway

    4: Stack launched

    3: Fetch template

  • Recap Serverless Application

    Created an AWS Serverless application

    Learned about the serverless.template file

    Exposed Lambda functions as a HTTP API

    Deployed using AWS CloudFormation

  • ASP.NET Core and Web API

    ASP.NET Core is the web framework for .NET Core

    Includes framework for building Web API applications

    Define API controllers to respond to requests

    Maps request data to function parameters


    public class ValuesController : Controller


    // PUT api/values/5


    public void Put(int id, [FromBody]string value)





  • How can we use ASP.NET Core in Lambda?

    Amazon API Gateway Proxy Integration

    Forwards all requests to a Lambda Function

    Lambda Function

    Converts how requests and responses are represented

    between API Gateway and ASP.NET Core

    Implemented by Amazon.Lambda.AspNetCoreServer

    NuGet package

    Currently in preview

  • ASP.NET Core Web API Architecture

    IIS / Nginx


    Core Hosting

    Users Web API Controllers


  • ASP.NET Core Architecture on Lambda

    API Gateway


    Core Hosting

    Users Web API Controllers


  • Demo:

    ASP.NET Core Web API

  • Recap ASP.NET Core Web API Demo

    Used existing ASP.NET Core framework

    No change to controller code

    Used API Gateway Proxy Integration to forward all


    Lambda function translates between API Gateway and

    ASP.NET Core

    Amazon.Lambda.AspNetCoreServer NuGet Package

    In preview

    Looked at the handler source in GitHub

  • Useful Links

    AWS Toolkit for Visual Studio

    AWS Lambda .NET GitHub

    AWS .NET Developer Blog

    AWS Lambda Developer Guide

    AWS Toolkit for Visual Studio Guide


  • Other Related Sessions

    CMP211 - Getting Started with Serverless Architectures

    SRV202 Whats New with AWS Lambda

    DEV301 - Amazon CloudWatch Logs and AWS Lambda: A Match Made in


    MBL306 - Serverless Authentication and Authorization: Identity Management

    for Serverless Architectures

    SVR311 - The State of Serverless Computing

  • Thank you!

  • Remember to complete

    your evaluations!