Date post: | 22-Jan-2018 |
Category: |
Technology |
Upload: | chris-obrien |
View: | 2,271 times |
Download: | 1 times |
Azure – the best bits (for Office 365/SharePoint devs)Chris O’Brien (MVP)Independent/Content and Code, UK
Add Speaker
Photo here
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!
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
Azure is… Big
> 90%Fortune 500 using MS cloud
>Active websites
300k 1,000,000
715Azure AD users
More than
SQL databases in Azure
120k PER
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
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
Deployment options
Drag and drop in browser (Kudu)
Publish from Visual Studio
WebDeploy
Source control integration (GitHub, Git, VS Online)
FTP
Azure Web Apps - deployment slots
Dev/test/prod “instances” of your site • Own URL
• Own App Settings/Connection Strings
http://mysite.azurewebsites.net
http://mysite-dev.azurewebsites.net
http://mysite-test.azurewebsites.net
Allows you to test purely in production Office 365 environment, BUT with dev/test/prod code!
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>
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
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
Getting started
ASP.NET web app
• NuGet package:
Install-Package Microsoft.ApplicationInsights
• https://www.nuget.org/packages/Microsoft.ApplicationInsights/
Modern web app
• npm package:
npm i applicationinsights
• https://www.npmjs.com/package/applicationinsights
Instrumentation key
Links your code to App Insights instance:
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?
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!
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!
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 JobsSee http://cob-sp.com/2r1MZe5
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.azurewebsites.net//api/CreateModernPage?code=FniGsXQ43Nf1HYB0JEIRuRrbLPaTTQnuithMnqtXoLQ54Hz6FY/j3g==
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#
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)
Stop storing things in SharePoint that should be in SQL!
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
Azure SQL DB sizes
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
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();
}
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-AzureRmResourceGroupDeployment–TemplateFilexyz
Building an ARM template
• The scope is a Resource Groupodreason to structure your resources in this way
• Export-AzureRmResourceGroup
• See https://azure.microsoft.com/en-us/blog/export-template
ARM templates – commandsNew-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
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
ARM templates – other features
Define dependencies, for
correct provisioning sequence
Tags
Role-based security
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
Decoupling code with a Queue
I take things from queue and process them e.g.- Azure Function- Azure Web Job
I put things on queue
QueueTriggerC#, REST etc.
What goes on a Queue?
Answer – a string (i.e. anything)
{“SiteUrl”: “/Project12345”,“Title”: “Project 12345”,“Template”: “ProjectSite”“Owners”: {
“Primary”: “[email protected]”,“Secondary”: “[email protected]”}
}
Create object
Serialize
Add to queue
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
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
http://cob-sp.com/
AzureQueues
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
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
Useful links
Azure Storage Explorer• https://AzureStorageExplorer.codeplex.com
Azure Functions / SPFx series• http://cob-sp.com/SPFx-AzureFunc-1
PnP Partner Pack• https://github.com/SharePoint/PnP-Partner-Pack
Thank you!!
Any questions?
www.sharepointnutsandbolts.com@ChrisO_Brien