4. 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
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
16. 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
17. 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
18. 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…