W I N 3 0 8 - R Developing serverless .NET Core on AWS
Norm Johanson Steve Roberts Senior Software Developer Senior Technical Evangelist Amazon Web Services Amazon Web Services
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agenda
What’s new for .NET development on AWS?
Demo app: CloudMosaic 2019 Edition © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS joins the .NET Foundation
The .NET Foundation is an independent organization run by a board of directors made up of fellow .NET community members. The foundation is working to foster innovation with .NET and support open-source projects. https://aws.amazon.com/blogs/opensource/aws-joins-the-net- foundation/ https://dotnetfoundation.org AWS Tools for PowerShell 4.0 https://aws.amazon.com/blogs/developer/aws-tools-for-powershell-is- now-generally-available-with-version-4-0/
Tools refactored to per-service modules plus common core
Adds support for mandatory parameter attribution
New options for selecting output AWS Toolkit for Rider
Available on the Rider Marketplace CloudMosaic sample is on GitHub https://github.com/aws-samples/cloudmosaic-dotnet
Includes workshop-style documentation so you can build and deploy to your own account © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is CloudMosaic? + = What does the application illustrate?
Developing modern, serverless, .NET applications on AWS AWS AWS AWS Step Lambda Batch Functions Using AWS SDK for .NET and tools for .NET to work with AWS services
Amazon Amazon AWS Systems Deploying to services using the DynamoDB Cognito Manager tools you are familiar with
AWS Toolkit for AWS extensions for Visual Studio the “dotnet” CLI Subsystems
Amazon Rekognition
AWS Lambda Batch
Amazon DynamoDB S3
AWS Parameter Fargate Amazon Amazon Store ECR S3
Mosaic rendering workflow Amazon S3
Amazon Amazon Cognito ECR Step Small Functions
Map Select Medium Notify colors tiles (F#)
Large Demo: CloudMosaic 2019 https://cloud-mosaic.com
https://github.com/aws-samples/cloudmosaic-dotnet CloudMosaic: What’s new?
• Improve usability and error handling
• Take advantage of latest AWS Lambda performance techniques
• Rearchitected Frontend with ASP.NET Core 3.0 © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Tile gallery
User supplies zip file AWS Batch process Serverless function containing multiple unpacks zip file and analyzes each image, images to be used as tiles uploads each image to resizes it, and saves as a cloud storage tile in a named gallery What did we want to improve? © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Recap: Tile gallery updates
Responding to DynamoDB Stream events • Events are batched • Update DynamoDB items with update expressions
Passing configurations through environment variables
Deploying Lambda functions with AWS CloudFormation © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mosaic workflow
Accepts an image file Analyzes the image Builds a new mosaic from the user plus the against the tile data in image using the name of a tile gallery the gallery matched tiles What did we want to change?
Error handling in AWS Step Function’s state machine
Take advantage of Lambda layers • Package common dependencies into a shared layer, smaller bundles • Pre-jit layer content to further optimize cold-start time AWS StepFunctions: State Machine © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Recap: Mosaic workflow updates
Adding error handling in state machines • Environment Variable: UNWRAP_AGGREGATE_EXCEPTION to true
Creating .NET runtime package store Lambda layers Deploying with layers © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Frontend application
Enabling signed-in users to:
Allowing user registration and Create new Upload an image authentication tile galleries to create a mosaic What did we want to change?
Add REST API project to support multiple clients (Web/Mobile)
Try ASP.NET Core 3.0 server-side Blazor on AWS
Take advantage of WebSockets in Amazon API Gateway to render progress REST API Project
ASP.NET Core 3.0 Web API Project
Authenticated with Amazon Cognito and JWT tokens
Hosted in Lambda and exposed to the web with an Application Load Balancer (ALB) within Elastic Load Balancing Hosting in Lambda
.NET Core 3.0 supported with Lambda Custom Runtimes and Amazon.Lambda.RuntimeSupport NuGet package
Blog post to migrate existing ASP.NET 3.0 Core applications to Lambda https://aws.amazon.com/blogs/developer/net-core-3-0-on-lambda-with-aws-lambdas- custom-runtime/
New ASP.NET Core 3.0 Lambda project from the command line dotnet new -i Amazon.Lambda.Templates dotnet new serverless.AspNetCore30WebAPI -o MyAspNet30CoreLambdaProject
Highly recommend using .NET Core 3.0 feature Ready To Run to improve Lambda cold starts ASP.NET Core Server Side Blazor on AWS
Blazor uses the real time communication framework SignalR to provide interactive web experience in .NET
SignalR needs a persistent connection to web server • CloudMosaic hosted using containers in Fargate registered to Application Load Balancer • Sticky sessions must be enabled
Authentication with Cognito Amazon.AspNetCore.Identity.Cognito NuGet package https://github.com/aws/aws-aspnet-cognito-identity-provider Reporting status from backend components
Amazon API Gateway provides WebSocket support
Lambda functions to handle connect, disconnect and authentication
Backend components broadcast messages to WebSocket using AWSSDK.ApiGatewayManagementApi NuGet package Recap: Frontend updates
Deploying an ASP.NET Core 3.0 Web API project to Lambda
Deploying an ASP.NET Core Server Side Blazor to Fargate
Hosting both Blazor frontend and Lambda API behind the same Application Load Balancer
Using Amazon API Gateway WebSockets to connect backend components to the frontend © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. cloud-mosaic.com Pipeline
Created from CloudMosaic-pipeline.template © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Recap
Learn how to write .NET Core AWS Lambda functions
Error handling in AWS Step Function’s state machines
Lambda performance techniques
Combining containers and Lambda functions with an Application Load Balancer
Authentication with Amazon Cognito and JWT tokens
Hosting ASP.NET Core 3.0 server-side Blazor with AWS Fargate
WebSockets to connect backend components with the frontend © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Useful resources
CloudMosaic repository • https://github.com/aws-samples/cloudmosaic-dotnet • re:Invent 2019 code in reinvent-2019 branch
GitHub AWS .NET Home • https://github.com/aws/dotnet
AWS .NET Blog • https://aws.amazon.com/blogs/developer/category/programing- language/dot-net/ Thank you!
Norm Johanson Steve Roberts @socketnorm @bellevuesteve
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.