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.

Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers


Published on

Discussion of Azure web apps, App Insights, "Azure Functions in the real world", ARM templates, queues, BLOB storage and more. Includes a video demo of AAD-secured Azure Function called from a SharePoint Framework (SPFx) web part with SPO cookie auth.

Published in: Technology
  • Be the first to comment

Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

  1. 1. Azure – the best bits (for Office 365/SharePoint devs) Chris O’Brien (MVP) Independent/Content and Code, UK Add Speaker Photo here
  2. 2. Top Office 365 + Azure scenarios What? How? Do something on a schedule Put code in Azure Web Jobs/Functions Build apps (Office 365 app/SP provider-hosted add-in) Deploy app files to an Azure app SharePoint site provisioning Deploy PnP Partner Pack to Azure Run code on a button click Use Azure Functions + JavaScript Store data not suited to SP lists Use Azure SQL Database Store files for my app Use Azure BLOB storage (and CDN if appropriate) Implement SharePoint web hooks Use Azure Queues and Functions Implement authentication on a custom web app Implement Azure Active Directory (AAD) auth Or the general case: HOST MY REMOTE SHAREPOINT CODE!
  3. 3. Some Azure features Compute •Virtual machines •App services/web apps •Web Jobs •Functions Storage •BLOB storage •Table storage •Queues •File service Data •Azure SQL Database •Redis cache •Azure Search •StorSimple •DocumentDB Messaging •Service Bus •Event Hubs •Queues/Topics/Relays Media • CDN • Encoding • Streaming Mobile services • Push notifications • Mobile Engagement Integration • Logic Apps • API management • Data Factory • Data Catalog Security and Identity • Azure Active Directory • AAD B2C • Azure RMS • Key Vault • MFA
  4. 4. Azure is… Big > 90% Fortune 500 using MS cloud > Active websites 300k 1,000,000 715Azure AD users More than SQL databases in Azure 120kPER MONTH12Orgs in Azure AD M > >> M 3Requests per second M > 30Storage objects TN > 2Developers in VS Online M New Azure subscriptions Performance Q2 2017 •93% revenue increase YoY •2x compute usage YoY
  5. 5. Web Apps A great hosting location • Easy to manage, scale up/down • Auto SSL/load-balancing/backup Perfect for extending SharePoint • Office 365 apps • SharePoint Add-ins • Standalone web apps Create Azure web app Register app in AAD/SP Configure Deploy files
  6. 6. Deployment options Drag and drop in browser (Kudu) Publish from Visual Studio WebDeploy Source control integration (GitHub, Git, VS Online) FTP
  7. 7. Azure Web Apps - deployment slots Dev/test/prod “instances” of your site • Own URL • Own App Settings/Connection Strings Allows you to test purely in production Office 365 environment, BUT with dev/test/prod code!
  8. 8. In Azure portal: PowerShell: “Swapping” deployment slots Slots can be swapped to deploy updates Actually a DNS update, not copy of content Process: Publish updates to dev/test slots Swap test/production when ready Switch-AzureWebsiteSlot –Name ‘COB website’ -Slot1 'Production' -Slot2 <slotName>
  9. 9. More Azure coolness – “Testing in production” Traffic Routing - send some traffic to another slot Uses: Testing new functionality on small number of users A/B testing
  10. 10. What is App Insights? Azure-based monitoring/reporting of your app • Exceptions • Events within your app Basic page analytics • (Not really suitable for site owners) Free up to 20GB per month
  11. 11. Getting started ASP.NET web app • NuGet package: Install-Package Microsoft.ApplicationInsights • packages/Microsoft. ApplicationInsights/ Modern web app • npm package: npm i applicationinsights • package/ applicationinsights
  12. 12. Instrumentation key Links your code to App Insights instance:
  13. 13. Log custom events/metrics How long does a (Graph?) API call take *for the user*? How often did a user click button X? What are the most popular file types?
  14. 14. 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, PowerShell etc. Simpler than a Web Job or Web API!
  15. 15. Functions – pricing plans App service plan Consumption plan Runs on dedicated VMs Serverless Pay for containing VM Pay for what you use (executions) Great if running at high scale Great for intermittent/quicker jobs Scale at VM level Scale up automatically MORE EXPENSIVE CHEAPER So, generally you want the consumption plan!
  16. 16. Functions vs. Web Jobs Similarities • Both can be scheduled or use trigger (queue/BLOB etc.) • Both support C#, JavaScript, PS Differences • Pricing - only Functions have pay-per-use option • Flexibility - Functions can be triggered from HTTP call/web hook, OneDrive, Github etc. • Restrictions – max 10 min timeout on Function Typically Functions > Web Jobs See
  17. 17. Authentication options Function auth • A simple code passed to function • Caller must know/store the code • Auth to Office 365/SP handled separately Azure AD auth • Function cannot be called without auth token • Requires adal.js/msal.js from JavaScript OR cookie/IFrame approach (currently) • OpenID Connect may help in SPFx in future? https://cob-pnp- functions.azurewebsite nPage? code= FniGsXQ43Nf1HYB0JEIRuR rbLPaTTQnuithMnqtXoLQ5 4Hz6FY/j3g==
  18. 18. Options for developing Azure Functions (C#) Use Azure portal • Good for playing around • No source control • Little coding support Use VS Code • Sync from source control to Function • Little coding support for C# (more for node.js) Use Visual Studio 2017 • Full coding support (F5 debug, IntelliSense) • Publish to Azure • Requires VS2017 15.3+ with Azure development workload .csx files and #r references True C#
  19. 19. Azure Functions in the real world Secured by AAD auth Identity of current user available if required Use of NuGet packages Uses App Insights for monitoring Uses PnP Core Callable from SPFx (with adal.js or cookie method)
  20. 20. Stop storing things in SharePoint that should be in SQL!
  21. 21. Benefits Get started faster than on-prem Don’t worry about backups (or patching) High availability Data replicated to 3 servers Pricing: - Free up to 20MB - Pay for data used
  22. 22. Azure SQL DB sizes
  23. 23. SQL in an Office 365 world Can now auth with AAD identity • No need for separate SQL auth/identity • Best practice – set AAD Group, not User to be admin Code options • Connect with certificate – app-only auth • Connect with user token (using MSAL or ADAL) – user auth
  24. 24. Create a new DB/add item with EF Entity Framework code: using (var db = new ListDbContext()) { List list = new List(); list.ListId = Guid.NewGuid(); list.WebId = Guid.NewGuid(); list.SiteId = Guid.NewGuid(); ListItem item = new ListItem(); item.List = list; item.ItemUniqueId = Guid.NewGuid(); item.Id = 1; db.Lists.Add(list); db.SaveChanges(); db.ListItems.Add(item); db.SaveChanges(); }
  25. 25. ARM templates Easily deploy without button clicks! Defined in JSON, deployed with PowerShell (or C# etc.) • Parameters extracted to separate file Deploy entire app, and optionally resources (e.g. code): • Web app (inc. App Settings, SSL cert etc.) • SQL Database • Function app • etc. New- AzureRmResource GroupDeployment –TemplateFile xyz
  26. 26. Building an ARM template • The scope is a Resource Groupod reason to structure your resources in this way • Export-AzureRmResourceGroup • See us/blog/export-template
  27. 27. ARM templates – commands New-AzureRmResourceGroupDeployment -ResourceGroupName foo –TemplateFile app.json -TemplateParameterFile params.json - Mode Incremental Test-AzureRmResourceGroupDeployment –TemplateFile xyz New-AzureRmResourceGroupDeployment -ResourceGroupName foo –TemplateFile app.json -TemplateParameterFile params.json - Mode Incremental
  28. 28. Advanced ARM scenarios Auto-deploying files for web app/Function • Zip file must exist in Azure BLOB storage • Auto-deploying SSL certs • Fetch bytes from filesystem, use in parameters object
  29. 29. ARM templates – other features Define dependencies, for correct provisioning sequence Tags Role-based security
  30. 30. Queues are great for.. Anything that should be picked up by a longer running task • SharePoint site provisioning • SharePoint web hooks • File processing (e.g. my image renditions demo) QueueTrigger – the key • Auto-runs your code (when new item added) • Azure Function • Azure Web Job
  31. 31. Decoupling code with a Queue Itake thingsfrom queue andprocessthem e.g. - AzureFunction - AzureWebJob Iput thingson queue QueueTriggerC#, REST etc.
  32. 32. What goes on a Queue? Answer – a string (i.e. anything) { “SiteUrl”: “/Project12345”, “Title”: “Project 12345”, “Template”: “ProjectSite” “Owners”: { “Primary”: “”, “Secondary”: “” } } Create object Serialize Add to queue
  33. 33. Adding a queue item // Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the queue client. CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); // Retrieve a reference to a queue. CloudQueue queue = queueClient.GetQueueReference(“SiteRequestQueue"); // Create a message and add it to the queue. CloudQueueMessage message = new CloudQueueMessage(siteInfoObject); queue.AddMessage(message); Other ops: - Peek message - Dequeue message - Amend contents of existing message
  34. 34. Storage Queues vs. Service Bus Queues Be aware of the two options.. ..but Storage Queues work well for most Key differences: Storage Queue Service Bus Queue 7 day max lifetime Unlimited lifetime Full transaction log No transaction log Order not guaranteed Order can be guaranteed Potential duplicates Duplicate detection Simpler More complex See AzureQueues
  35. 35. And we didn’t even talk about…! Azure Containers (Docker) API management Virtual machines (of course!) Azure RMS Azure B2C Azure mobile apps (e.g. notification hub) HDInsight Azure Data Lake Azure virtual networks Azure media services Azure batch (HPC) Azure backup vault
  36. 36. Key take-aways Web apps are cooler than you think! Write your first Azure Function! Perfect for timer jobs, perfect for web APIs (e.g. advanced web parts) Try deploying the PnP Partner Pack as a good exercise (manual approach) Deployment slots App Insights Testing in production
  37. 37. Useful links Azure Storage Explorer • Azure Functions / SPFx series • PnP Partner Pack •
  38. 38. Thank you!!  Any questions? @ChrisO_Brien