chris o'brien - best bits of azure for office 365/sharepoint developers

47
Azure – the best bits (for Office 365/SharePoint devs) Chris O’Brien (MVP) Independent/Content and Code, UK Add Speaker Photo here

Upload: chris-obrien

Post on 22-Jan-2018

2.269 views

Category:

Technology


1 download

TRANSCRIPT

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

Azure – the best bits (for Office 365/SharePoint devs)Chris O’Brien (MVP)Independent/Content and Code, UK

Add Speaker

Photo here

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

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!

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

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

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

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

Page 5: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 6: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

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

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

Deployment options

Drag and drop in browser (Kudu)

Publish from Visual Studio

WebDeploy

Source control integration (GitHub, Git, VS Online)

FTP

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

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!

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

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>

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

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

Page 11: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 12: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 13: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

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

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

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

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

Instrumentation key

Links your code to App Insights instance:

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

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?

Page 17: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 18: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

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!

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

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!

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

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

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

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==

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

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#

Page 23: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 24: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

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)

Page 25: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 26: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

Stop storing things in SharePoint that should be in SQL!

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

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

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

Azure SQL DB sizes

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

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

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

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();

}

Page 31: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 32: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

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

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

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

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

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

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

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

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

ARM templates – other features

Define dependencies, for

correct provisioning sequence

Tags

Role-based security

Page 37: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 38: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

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

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

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.

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

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

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

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

Page 42: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Page 43: Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers

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

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

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

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

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

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

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

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

Thank you!!

Any questions?

www.sharepointnutsandbolts.com@ChrisO_Brien