Ask me how I
Why Functions?
Web Jobs
WebApps
WebJobs
Where Functions Live?
Functions
App Service Hosting Plan
Dedicated Hosting Plan Consumption Plan
• Basic, Standard, Premium
• Pay based on # of reserved VMs
• You’re responsible for scale
• Pay on number of executions
• Platform responsible for scale
• Max execution time is 5 mins
Azure Functions Architecture
Consumption Plan Pricing (Dynamic Tier)
Pay per execution, 2 meters, 3 units
- Number of executions
- Execution duration (sec) X reserved memory (GB)
- Monthly 1 Million executions + 400,000GB-sec FREE
- After that $0.000016 GB-sec & $0.20 per Million Executions
https://azure.microsoft.com/en-us/pricing/details/functions/
- OR use an existing App Plan ;)
- Functions should “do one thing”
- Functions should be idempotent
- Functions should finish as quickly as possible
1
What Functions Should Do
Functions Basics
- Input trigger(s)
- Body
- Optional return value(s)
Triggers
Type Service Trigger Input Output
Schedule Azure Functions ✔
HTTP (REST or webhook) Azure Functions ✔ ✔*
Blob Storage Azure Storage ✔ ✔ ✔
Events Azure Event Hubs ✔ ✔
Queues Azure Storage ✔ ✔
Tables Azure Storage ✔ ✔
Tables Azure Mobile Apps ✔ ✔
No-SQL DB Azure DocumentDB ✔ ✔
Push Notifications Azure Notification Hubs ✔
Twilio SMS Text Twilio ✔
* requires an HTTP trigger
SaaS File (OneDrive, Google Drive, DropBox, etc)
SaaS Table (SalesForce, Dynamics, Google Sheets, etc)
Bindings - Declarative
Using function.json
Bindings - Imperative
Using IBinder or Binder parameter
Show me the money code!
Prerequisites
- A browser
- Node.js (2nd part)
Demo 1: Exposing a function on the web
- HttpTrigger
- Authorization level
Demo 2: Azure Function Proxies
- Versioning our Function
- To proxy or not to proxy, that is the question
Demo 3: Debugging Functions - Azure Portal
- Using HTTP headers/query parameters
Demo 4: Debugging Functions - Visual Studio 2017
- Requires npm package: npm i -g azure-functions-cli
- A standard ASP.NET WebApp empty project
- Start action: external program
- Program: %appdata%npmnode_modulesazure-functions-clibinfunc.exe
- Arguments: host start
- Working directory: directory of the function app
- Initiate function app: func init
- Generate a function under fuction app: func new
- Include function under function app in VS solution: function <name> folder
- Include function app files in VS solution: appsettings.json & host.json
Demo 5: Function as a .NET class library
- Take an existing function app from portal or create a new
- Update function.json to point to an assembly:
- "scriptFile": "..binAssembly.dll",
- "entryPoint": "Namespace.ClassName.Run"
- Convert .csx into a class
- Add the required packages:
- Microsoft.Azure.WebJobs
- Microsoft.Azure.WebJobs.Extensions
- Microsoft.AspNet.WebApi.Client
- Microsoft.AspNet.WebApi.Core
- xcopy deployment
- host.json → sitewwwroot
- function.json → sitewwwroot<function app folder>
- Download publish settings
- Publish using the settings
OR
Best Practices
- Avoid large long running functions
- Cross function communication (ASQ/ASB)
- Take advantage of dead letter queues
- Write functions to be stateless
- Write defensive functions
- Use async code. Yes, with ConfigureAwait(false)
- Don’t use Task.Result
- Chaining functions can be a challenge – wait till Build2017…
Chaining Functions: Monitored Thumbnail Generator
Use case: ETL (Failure Auditing)
https://weblogs.asp.net/sfeldman/azure-functions-to-make-audit-queue-and-auditors-happy
Use case: Message Deduplication
http://microsoftintegration.guru/2016/09/20/use-azure-function-to-deduplicate-messages-on-azure-service-bus/
Use case: Updates Notifier
NuGet packages
Thank you!
Connect @sfeldman / feldman.sean@gmail.com
Blog https://weblogs.asp.net/sfeldman
Tools
• Azure Portal
• npm azure-functions-cli https://www.npmjs.com/package/azure-functions-cli

Azure Functions @ global azure day 2017

  • 2.
  • 3.
  • 4.
    WebApps WebJobs Where Functions Live? Functions AppService Hosting Plan Dedicated Hosting Plan Consumption Plan • Basic, Standard, Premium • Pay based on # of reserved VMs • You’re responsible for scale • Pay on number of executions • Platform responsible for scale • Max execution time is 5 mins
  • 5.
  • 6.
    Consumption Plan Pricing(Dynamic Tier) Pay per execution, 2 meters, 3 units - Number of executions - Execution duration (sec) X reserved memory (GB) - Monthly 1 Million executions + 400,000GB-sec FREE - After that $0.000016 GB-sec & $0.20 per Million Executions https://azure.microsoft.com/en-us/pricing/details/functions/ - OR use an existing App Plan ;)
  • 7.
    - Functions should“do one thing” - Functions should be idempotent - Functions should finish as quickly as possible 1 What Functions Should Do
  • 8.
    Functions Basics - Inputtrigger(s) - Body - Optional return value(s)
  • 9.
    Triggers Type Service TriggerInput Output Schedule Azure Functions ✔ HTTP (REST or webhook) Azure Functions ✔ ✔* Blob Storage Azure Storage ✔ ✔ ✔ Events Azure Event Hubs ✔ ✔ Queues Azure Storage ✔ ✔ Tables Azure Storage ✔ ✔ Tables Azure Mobile Apps ✔ ✔ No-SQL DB Azure DocumentDB ✔ ✔ Push Notifications Azure Notification Hubs ✔ Twilio SMS Text Twilio ✔ * requires an HTTP trigger SaaS File (OneDrive, Google Drive, DropBox, etc) SaaS Table (SalesForce, Dynamics, Google Sheets, etc)
  • 10.
  • 11.
    Bindings - Imperative UsingIBinder or Binder parameter
  • 12.
    Show me themoney code! Prerequisites - A browser - Node.js (2nd part)
  • 13.
    Demo 1: Exposinga function on the web - HttpTrigger - Authorization level
  • 14.
    Demo 2: AzureFunction Proxies - Versioning our Function - To proxy or not to proxy, that is the question
  • 15.
    Demo 3: DebuggingFunctions - Azure Portal - Using HTTP headers/query parameters
  • 16.
    Demo 4: DebuggingFunctions - Visual Studio 2017 - Requires npm package: npm i -g azure-functions-cli - A standard ASP.NET WebApp empty project - Start action: external program - Program: %appdata%npmnode_modulesazure-functions-clibinfunc.exe - Arguments: host start - Working directory: directory of the function app - Initiate function app: func init - Generate a function under fuction app: func new - Include function under function app in VS solution: function <name> folder - Include function app files in VS solution: appsettings.json & host.json
  • 17.
    Demo 5: Functionas a .NET class library - Take an existing function app from portal or create a new - Update function.json to point to an assembly: - "scriptFile": "..binAssembly.dll", - "entryPoint": "Namespace.ClassName.Run" - Convert .csx into a class - Add the required packages: - Microsoft.Azure.WebJobs - Microsoft.Azure.WebJobs.Extensions - Microsoft.AspNet.WebApi.Client - Microsoft.AspNet.WebApi.Core - xcopy deployment - host.json → sitewwwroot - function.json → sitewwwroot<function app folder> - Download publish settings - Publish using the settings OR
  • 18.
    Best Practices - Avoidlarge long running functions - Cross function communication (ASQ/ASB) - Take advantage of dead letter queues - Write functions to be stateless - Write defensive functions - Use async code. Yes, with ConfigureAwait(false) - Don’t use Task.Result - Chaining functions can be a challenge – wait till Build2017…
  • 19.
    Chaining Functions: MonitoredThumbnail Generator
  • 20.
    Use case: ETL(Failure Auditing) https://weblogs.asp.net/sfeldman/azure-functions-to-make-audit-queue-and-auditors-happy
  • 21.
    Use case: MessageDeduplication http://microsoftintegration.guru/2016/09/20/use-azure-function-to-deduplicate-messages-on-azure-service-bus/
  • 22.
    Use case: UpdatesNotifier NuGet packages
  • 23.
    Thank you! Connect @sfeldman/ feldman.sean@gmail.com Blog https://weblogs.asp.net/sfeldman Tools • Azure Portal • npm azure-functions-cli https://www.npmjs.com/package/azure-functions-cli

Editor's Notes

  • #17 Run VS as admin or functions CLI won’t be executed properly