Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

48
Azure Update, July Kanio Dimitrov

Transcript of Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Page 1: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Azure Update, JulyKanio Dimitrov

Page 2: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Main Azure Updates• VM - General availability of IaaS migration from classic to Resource

Manager

• Storage - General availability: Azure cool blob storage in Canada

• Azure Redis Cache: Preview of new administration options in Premium tier• Reboot• Schedule updates

Page 3: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Main Azure Updates• Azure Automation : Time zone support and daylight savings

• General availability: Always Encrypted for Azure SQL Database

• Public preview: New version of Azure Active Directory PowerShell cmdlets

• General availability: Azure ExpressRoute in additional locations• Paris, Newport/Wales, and Quebec City

Page 4: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Main Azure Updates• General availability: Two new Azure regions (West US 2 and West

Central US)

• General availability: SQL Server Stretch Database

• General availability: Microsoft Power BI Embedded

• General availability: Microsoft R Server for Linux virtual machines

Page 5: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Main Azure Updates• Microsoft introduces AppSource for SaaS business apps

• Public preview: Cortana Intelligence Suite with Bing Predicts

• General availability: Microsoft Azure IoT Hub S3 edition• 300 million messages per day

• General availability: Bing APIs in Microsoft Cognitive Services• Autosuggestion API, Spell Check API, Search API

Page 6: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Main Azure Updates• Preview: Microsoft R Client

• G-Series instances for Azure Virtual Machines available in Australia East

• General availability: Azure SQL Data Warehouse

• Azure App Service Authentication and Azure AD domain hints

Page 7: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Main Azure Updates• General availability: Service Bus Premium Messaging released to

general availability

• Azure DevTest Labs: Attach additional data disk to your lab VM

• General availability: Azure portal updates for Azure Stream Analytics:• Power BI Output• Data Lake Output• Simple Input

Page 8: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Introduction to Serverless Architecture

Kanio Dimitrov

Page 9: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

About Me

Azure MVP, Architect & Advisor

Tokyo Azure Meetup Host

twitter: @azurekanio

blog: https://azurekan.wordpress.com/

Page 10: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Serverless Computing

Serverless computing refers to a model where the existence of servers is simply hidden from developers.

• Major shift in Cloud Computing

• Application Code Focus

• Cost Effectiveness

Page 11: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016
Page 12: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Microservices

Small Autonomous services that model business domain and have single responsibility

Recommendations

Inventory

Orders

Shopping Cart

Shipping

Monolithic System

Page 13: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Serverless Microservices

Order Microservice

GET Order

Create Order

Update Order

Remove OrderAPI

GatewayMobileClient

Page 14: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Serverless Principles

• Abstract completely underlying infrastructure

• Break business logic to functions

• Focus only on application code

• True auto scaling in seconds

• Integrate with external systems

Page 15: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Current State• AWS Lambda – market leader

• Google Cloud Functions

• Azure Functions – in Preview

• Auth0 Webtasks

• IBM OpenWhisk

Page 16: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Modern Ops Requirements• Engineers are responsible for the operational quality

• Software Engineers have to value operational excellence

• Software Engineers on call for their own services

• Ops skills are not optional for software engineers in 2016

• Software engineers own their systems from end to end

Page 17: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Modern Ops Requirements• The other side of DevOps - Software engineers need to level up at

operations

• Outsource as many ops responsibility as possible

• Build operational excellence for core business differentiators

• Aggregate metrics and graph them

Page 18: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

DevOps requires time• Biggest obstacle to

innovation is that development times are too long

• DevOps adds to the development time

• Application builders need to manage their server infrastructure

Page 19: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Serverless Advantages• Rapid Development

• Truly Polyglot

• Event Driven

• Minimal Maintenance

• Very Scalable

• Pay Per Use

Page 20: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Serverless Disadvantages• Limited transparency

• Immature tooling (debugging and troubleshooting)

• Required security review and penetration testing guidance

• More and better documentation and best practices

• Vendor Lock-in (Huge dependency on cloud provider)

• Limits not well defined

Page 21: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Azure Functions

Input Code Output

• Trigger - specify what conditions cause the function to be called• Binder - specify how to get information into and out of method

parameters

Page 22: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Azure Functions vs Web Jobs• Web Jobs:

• + Extendable. Can run whatever you we want. Full control• - HTTP functionality requires more effort to be configured

• Functions:• + Many languages supported• + Completely managed with dynamic scaling• + Portal experience simplifies a lot development• - Host can’t be customized yet• - We are using dedicated "app" which requires additional configuration, but in long term is

advantage• - Better tooling required

Page 23: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Binding Integration

Page 24: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Time Based Processing

Page 25: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Azure service event processing

Page 26: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

SaaS event processing

Page 27: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Serverless web application architectures

Page 28: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Serverless mobile backends

Page 29: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Real-time stream processing

Page 30: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Real-time bot messaging

Page 31: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Supported Platforms• C#• F#• JavaScript• Python• PHP• Bash• Batch• PowerShell

Page 32: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Demo – Hello World!

Page 33: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Let’s focus on C#

• .csx file – focus on writing business logic function

• Do not design classes and namespace, just Run method

• POCO classes inside the same file for data processing

Page 34: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Async & Cancellation Token• async keyword

• Task return type

public async static Task ProcessBlobEvent(Stream blobInput, Stream blobOutput, CancellationToken token){

await blobInput.CopyToAsync(blobOutput, 4096, token);}

Page 35: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Namespaces• Use using• Automatically imported:• System• System.Collections.Generic• System.IO• System.Linq• System.Net.Http• System.Threading.Tasks• Microsoft.Azure.WebJobs• Microsoft.Azure.WebJobs.Host

Page 36: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Framework Assemblies• Use #r "AssemblyName“• Automatically added:

• mscorlib• System• System.Core• System.Xml• System.Net.Http• Microsoft.Azure.WebJobs• Microsoft.Azure.WebJobs.Host• Microsoft.Azure.WebJobs.Extensions• System.Web.Http• System.Net.Http.Formatting

Page 37: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Special Case• Use only #r "AssemblyName“

• Newtonsoft.Json•Microsoft.WindowsAzure.Storage•Microsoft.ServiceBus•Microsoft.AspNet.WebHooks.Receivers•Microsoft.AspNEt.WebHooks.Common

Page 38: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Custom Assemblies

• Upload them to bin folder for the function:• Azure Portal• Kudu• FTP

• Reference using the file name - #r "MyAssembly.dll"

Page 39: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Packages• Upload project.json file to the function’s folder

• Specify NuGet packages

{ "frameworks": { "net46": { "dependencies": { "Microsoft.ProjectOxford.Face": "1.1.0" } }

} }

Page 40: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Configuration

• Via Environment variables

• Set on App Service Level

• Use System.Environment.GetEnvironmentVariable:• GetEnvironmentVariable(“FacialRecognitionApiKey”);

Page 41: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Code Reuse

• Use classes and methods defined in other .csx files in your run.csx file

• To do that, use #load directives in your run.csx file:• #load “logger.csx”

Page 42: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Logging

• Include a TraceWriter typed argument

• Recommended to name it log

• Don’t use Console.Write

Page 43: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Hosting Options

• App Service Plan

• Dynamic Service Plan• Dynamically allocated resources• Functions will run in parallel• Memory from 128 MB to 1536 MB• Limited support for App Service features

Page 44: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Development, Debugging & Testing• Local Development is coming

• Live debugging with Visual Studio

• Azure Storage Explorer

• HTTP Endpoints testing:• Postman, Fiddler, Browser

Page 45: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Scaling

• Classic App Serivce Plan scales based on set rules

• Dynamic Service plan scales independently based on traffic

•Major criteria is memory size of the execution environment

Page 46: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Pricing – “pay-per-user”

• Price = Memory size (in GB) x Total amount of execution time (in secs)

• Execution time – active time for all functions running inside that function app

• Unit of consumption will be GB-s (Gigabyte Seconds)

Page 47: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Demo – Azure Functions Scenarios

Page 48: Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure Functions, July 2016

Next Tokyo Azure Meetup• Date – August, 29-th

• Time – 19:30 – 21:00

• Location – Microsoft Office

• Topic: DevOps / Azure Functions Deep Dive / Bot Framework or another topic. What is the most interesting one for you?