Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

COB - Azure Functions for Office 365 developers


Published on

A presentation I gave at ESPC 2018 (the European SharePoint, Office 365 and Azure Conference) about use of Azure Functions to extend Office 365 solutions. Covers Azure Functions fundamentals, adding code to PowerApps/Flow, Site Designs and Site Scripts (and PnP site templating), SPFx and Durable Functions. Also has tips on v1/v2, performance, pricing and how to avoid cold starts.

Published in: Technology
  • Be the first to comment

COB - Azure Functions for Office 365 developers

  1. 1. An A-Z of Azure Functions (for Office 365 scenarios) Chris O’Brien (MVP) Independent/Content and Code
  2. 2. Simpler than a Web Job or Web API! Simple code hosting Scenarios • Button click (e.g. web part) • Scheduled process • Respond to event (e.g. new file in Azure) Develop in any language • C#, JavaScript, PHP, PowerShell (maybe)
  3. 3. Functions – use cases (Bold items are demo scenarios) Use case Scheduled job (timer function) Utility code with PnP Call from SPFx web part Call from PowerApps Call from Flow Site provisioning – site designs Site provisioning – other Also perfect for hiding implementation/ secrets from client
  5. 5. Visual Studio, VS Code, or CLI? Approach Best for Why Visual Studio C# functions • Easiest C# local debugging • Good all-rounder for functions Visual Studio Code Other languages (e.g. JavaScript) • Good JS debugging support • Natural fit for JS development CLI CI/CD scripts Hipsters • Debugging still needs VS Code Azure-Functions-3-ways
  6. 6. Triggers - what causes me to run? Trigger type Data to process Timer Queue Azure BLOB – e.g. new file HTTP (e.g. from a web part/PowerApps/Flow) Graph – OneDrive file, Excel row, Outlook e-mail etc. Event Grid Cosmos DB --- PLUS LOTS MORE ---
  7. 7. Triggers - what causes me to run? Trigger type Data to process Timer Schedule, if delayed run Queue Queue message contents + metadata Azure BLOB – e.g. new file File metadata and contents HTTP (e.g. from a web part/PowerApps/Flow) Data in URL/body/headers + parameters passed Graph – OneDrive file, Excel row, Outlook e-mail etc. Appropriate data Event Grid Event data Cosmos DB New/changed data --- PLUS LOTS MORE ---
  8. 8. DEMO – creating Azure Functions
  9. 9. Demo recap Create function app in Azure •(but can be done in Visual Studio/VS Code) Switch function to v1 (for now) if using CSOM/PnP libraries Code Debug locally Publish to DEV Azure subscription
  10. 10. Deployment options Drag and drop in browser (Kudu) Publish from Visual Studio WebDeploy Source control integration (GitHub, Git, VS Online) FTP
  11. 11. AZURE FUNCTIONS AND POWERAPPS/FLOW Custom connectors
  12. 12. Azure Functions and PowerApps/Flow • Break out of constraints! • Integrate custom data sources (e.g. write back to HR system) • Avoid doing crazy code-like things in a Flow
  13. 13. Azure Functions and PowerApps/Flow - process Use in PowerApps/Flow Create connector from connection – define security, make usable Export to PowerApps/Flow Create Open API definition – methods/parameters Create Function and deploy
  14. 14. DEMO – Azure Functions and Flow
  15. 15. THINGS YOU SHOULD KNOW v1 vs. v2, pricing, service plans, gotchas, cold starts..
  16. 16. Runtime versions 1 and 2 Azure Functions v1 Built on full .NET Framework Less performant Bindings internalised Some languages experimental (e.g. PowerShell) Slower cold starts Azure Functions v2 Built on .NET Core More performant Bindings externalised Language support clarified (no PowerShell for now!) Faster cold starts
  17. 17. Consumption plan vs. App Service plan Free (per month): • 1 million executions • 400,000 GB-sec • (average memory size [gigabytes] * execution time [milliseconds]) Consumption plan App service plan Serverless Runs on dedicated VMs Pay for what you use (executions) Pay for containing VM Great for intermittent/quicker jobs Great if running at high scale Scale up automatically Scale at VM level CHEAPER MORE EXPENSIVE (usually)
  18. 18. Consumption plan - BE AWARE Function timeout = 5 minutes (can be increased to 10) Function app limited to 1.5GB memory Cold start - process goes idle after 20 mins Possible delays in some triggers (e.g. new files) App Service plan is different, because you’re running on your own dedicated VMs..
  19. 19. Cold start mitigation strategies OPTION 1 – make sure your function runs every 20 mins! OPTION 2 – use my “endpoint keep-warm” solution or similar OPTION 3 – use App Insights Function-Warmup
  20. 20. Top gotchas with Azure Functions • v1 is locked to Newtonsoft.Json 9.0.1 – so need to use v1 and SharePointPnPCoreOnline 2.24.1803 for now (.NET Core versions soon!) Using PnP Core and CSOM? • Only possible when Function App exists but has no functions! Need to switch between v1/v2? • Always store client object (e.g. HttpClient) as static variable Making HTTP requests (e.g. to Graph) or other connections? • More versioning issues for now – resolved soon Using MSI and Key Vault with PnP/CSOM? • Take care with cold starts and timeouts Need fast perf immediately?
  21. 21. SPFx web part -> Azure Function
  22. 22. Output bindings – codeless magic! Example: [FunctionName("QueueTrigger")] [return: Blob("output-container/{id}")] public static string Run([QueueTrigger("inputqueue")]WorkItem input, TraceWriter log) { string json = string.Format("{{ "id": "{0}" }}", input.Id); log.Info($"C# script processed queue message. Item={json}"); return json; } Output bindings - your Function can automatically: • Add a queue item • Create a file • Add an item to a table in Azure Storage • Make a HTTP call • Create a OneDrive file • Etc. No code is required!
  23. 23. SITE DESIGNS AND AZURE FUNCTIONS Modern site provisioning
  24. 24. Site designs = modern site provisioning Key benefits: • Template sites for Microsoft Teams and Office 365 Groups and: • Team sites • Communication sites • Hub sites • Integrated into Office 365 UI
  25. 25. Site design capabilities • Site settings – theme, logo, regional settings, permissions, external sharing • Create lists and libraries (with columns, content types, views etc.) • Install SPFx solution (e.g. web part) • Register an SPFx extension (e.g. header, footer) • Trigger a Flow • Join a hub site (when site created from this template) • Limited to 50 actions currently
  26. 26. But what happens when I need more? • Answer – you plug in an Azure Function to apply a PnP template! See
  27. 27. But what happens when I need more? A simplified view: See Site design Flow Adds item to queue Azure Function runs (queue trigger) Runs code/applies PnP template
  28. 28. Add a Site Design/Site Script:
  29. 29. Integration – Site Design and Function See
  30. 30. DEMO – Site Designs and Azure Functions/PnP
  31. 31. Pimp your function! Enterprise use: service/app-service-managed-service-identity service-identity-with-key.html NuGet = Microsoft.ApplicationInsights
  33. 33. Durable Functions See functions/durable-functions-overview • Pattern 1 - chaining: • Beat the 5/10 minute timeout! • Create site collection > apply partial PnP template 1 > apply partial PnP template 2 > finish Orchestrator function calls child functions Persist variables across executions
  34. 34. Durable Functions See functions/durable-functions-overview Orchestrator function calls child functions Persist variables across executions • Pattern 2 – fan-out: • Do lots of SharePoint updates at once! (but watch for throttling/429s!)
  35. 35. Some things from me https://cob- ways Warmup Thank you!!  Any questions? @ChrisO_Brien
  36. 36. Summary HTTP/timer functions SPFx web partsSecurely calling a web API PowerApps/Flow Site Designs/provisioning (inc. Teams) Don’t wait for v2 CSOM/PnP Current challenges are small compared to benefits Azure Functions are great for…