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.
Presentation on how to chat with PDF using ChatGPT code interpreter
An A-Z Guide to Using Azure Functions for Office 365 Scenarios
1. An A-Z of Azure Functions
(for Office 365 scenarios)
Chris O’Brien (MVP)
Independent/Content and Code
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. 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. 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
https://cob-sp.com/
Azure-Functions-3-ways
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. 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 ---
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. Deployment options
Drag and drop in browser (Kudu)
Publish from Visual Studio
WebDeploy
Source control integration (GitHub, Git, VS Online)
FTP
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. 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
15. THINGS YOU SHOULD KNOW
v1 vs. v2, pricing, service plans, gotchas, cold starts..
16. Runtime versions 1 and 2
https://azure.microsoft.com/en-us/blog/introducing-azure-functions-2-0/
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. 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. 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.
20. 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
https://cob-sp.com/Azure-
Function-Warmup
21. 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?
23. 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!
25. 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
26. 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
27. But what happens when I need more?
• Answer – you plug in an Azure Function to apply a PnP template!
See https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-trigger-flow-tutorial
28. But what happens when I need more?
A simplified view:
See https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-trigger-flow-tutorial
Site design Flow
Adds item to
queue
Azure
Function
runs (queue
trigger)
Runs
code/applies
PnP
template
30. Integration – Site Design and Function
See https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-trigger-flow-tutorial
36. Some things from me
https://cob-
sp.com/AzureFunctionsVideos
https://cob-sp.com/Azure-Functions-3-
ways
https://cob-sp.com/Azure-Function-
Warmup
Thank you!!
Any questions?
www.sharepointnutsandbolts.com
@ChrisO_Brien
37. 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…
Editor's Notes
To add your image, please insert your picture and scale it to be bigger than the size of the white box shown.