42
Windows Azure Mobile Services: The Perfect Partner Michael S. Collier @MichaelCollier CodeMash – January 9, 2014

Windows Azure Mobile Services - The Perfect Partner

Embed Size (px)

Citation preview

Page 1: Windows Azure Mobile Services - The Perfect Partner

Windows Azure Mobile Services: The Perfect Partner

Michael S. Collier@MichaelCollier

CodeMash – January 9, 2014

Page 2: Windows Azure Mobile Services - The Perfect Partner

Michael S. Collier

• Principal Cloud Architect, Aditi

[email protected]• @MichaelCollier• www.MichaelSCollier.com

Page 3: Windows Azure Mobile Services - The Perfect Partner

UPCOMING WINDOWS AZURE EVENTSDevUnleashed

Saturday, February 8th Microsoft – Columbus Michael Collier, Samidip Basu, Jared Faris, or Mike Wood

Global Windows Azure Boot Camp Saturday, March 29th http://global.windowsazurebootcamp.com Michael Collier, Brian Sherwin, or Mike Wood

CloudDevelop Friday, August 15th 2014 Ohio Union – The Ohio State University www.CloudDevelop.org / @CloudDevConf Michael Collier or Jared Faris

Page 4: Windows Azure Mobile Services - The Perfect Partner

CLOUD / MOBILE USER GROUPS

Central Ohio Cloud Computing User Group Windows Azure, AWS, Google, etc

2nd Monday of each month

6pm – 8pm

Improving Enterprises, Columbus

www.coccug.org

@coccug

Michael Collier

Windows Developer User Group Windows Store & Windows Phone

3rd Monday of each month

6pm – 8pm

TechColumbus

http://thewindowsdeveloperusergroup.com/

@WindowsDevUG

Samidip Basu

Page 5: Windows Azure Mobile Services - The Perfect Partner

Agenda

• What is it? / Getting Started• Data Storage Options• Server Scripts / Business Logic• Push Notifications• User Authentication• Diagnostics / Monitoring

• Q & A6

Page 6: Windows Azure Mobile Services - The Perfect Partner

Mobile Backend-as-a-Service (MBaaS)

Identi

ty

Str

uct

ure

d

Sto

rag

e

Mess

ag

ing

Sch

ed

ule

d T

ask

s

Unst

ruct

ure

d

Sto

rag

e

Windows Azure Mobile ServicesWindows Azure Mobile Services

Ad

dit

ional

Serv

ices

Page 7: Windows Azure Mobile Services - The Perfect Partner

What is Windows Azure Mobile Services

Data

Notifications

Auth

Server Logic

Scheduling

Logging

Diagnostics

http://aka.ms/mobileservicesImage courtesy of Windows Azure Training Kit

Page 8: Windows Azure Mobile Services - The Perfect Partner

Client Support

Windows Phone Windows Store AndroidiOSHTML5Xamarin.iOSXamarin.AndroidSencha

Image courtesy of http://msdn.microsoft.com/en-us/library/windowsazure/jj554228

Page 9: Windows Azure Mobile Services - The Perfect Partner

12

DEMO TIME!!!

Page 10: Windows Azure Mobile Services - The Perfect Partner

Shhh . . . It’s a Secret

Application KeyNOT A SECURITY TOKEN/CONTROLHint that user is coming from your app (reduce chance of misuse)

Private until you publish the app

Master KeyAll powerfulDo NOT distribute with your applicationUse from server-side logic you control

Page 11: Windows Azure Mobile Services - The Perfect Partner

Unstructured Data Storage

Leverage Windows Azure Storage or Service BusTables: schemaless entity storage; NoSQLBlobs: storage for any binary object (files . . . whatever you want)Queues: simple messaging (push/pop)

Access via Windows Azure module for node.jsvar azure = require('azure');var tableService = azure.createTableService(‘<storage account>',‘<storage key>', 'table.core.windows.net');tableService.insertEntity(‘<table>’, entity, function(error) { });

Page 12: Windows Azure Mobile Services - The Perfect Partner

Structured Data Storage

Leverage strengths of Windows Azure SQL DatabaseNew or Existing DatabaseReporting, TSQL support, existing tools, etc.Manage your way (portal, REST API, SSMS, etc.)

Partition applications by schemamycoupons.Usersspeakers.Users

Dynamic Schema Support (on/off)

Page 13: Windows Azure Mobile Services - The Perfect Partner

Default System Columns

Column Type Description

id string Any unique stringIf not provided, server will create a unique value (GUID)

__createdAt date Set when item is inserted

__updatedAt date Set anytime there is an update to the item.Updated via database trigger.

__version timestamp Unique value updated anytime there is a change to the itemRead-only value

16

• Columns starting with ‘__’ (two underscores) will be rejected.• System columns not returned by default. Set ‘__systemProperties’ on request or

‘systemProperties’ in server

• azure mobile table create --integerId [service_name] [table_name]

More info at http://blogs.msdn.com/b/carlosfigueira/archive/2013/11/23/new-tables-in-azure-mobile-services-string-id-system-properties-and-optimistic-concurrency.aspx

Page 14: Windows Azure Mobile Services - The Perfect Partner

Data Access

REST APIOData InterfaceGET, POST, PATCH, DELETE

https://<service>.azure-mobile.net/tables/<table_name>/{<item_id>}

AuthorizationX-ZUM0-{APPLICATION | AUTH | MASTER}

Send JSON in request bodyReceive JSON as response

Page 15: Windows Azure Mobile Services - The Perfect Partner

18

DEMO TIME!!!

Page 16: Windows Azure Mobile Services - The Perfect Partner

Server-Side Business Logic

• Never trust the client!• Handled via JavaScript scripts on the server• Intercept CRUD operations and apply your

logicPre

-S

crip

ting

Scripting

Pre

-Sto

rag

e

node.js

User authenticationPayload verification

Dynamic schematizationFinal checks

function(item, user, request) {…..}

Page 17: Windows Azure Mobile Services - The Perfect Partner

node.js

Known objects and modulesapnsazureconsolecryptogcmmpnsmssqlpushqueryrequestresponseservicesendgrid statusCodestableuserutil

var SendGrid = require('sendgrid').SendGrid;var sendgrid = new SendGrid(‘<account>', ‘<password>'); sendgrid.send({ to: userItem.EmailAddress, from: '[email protected]', subject: 'New ToDoItem Added!!', text: 'A new MyToDoItem was added: ' + item.text}, function(success, message) { // If the email failed to send, log it as an error. if (!success) { console.error('SendGrid Error! ' + message); } });

Page 18: Windows Azure Mobile Services - The Perfect Partner

Source Control

• Enable via a Git repository• Portal• azure mobile preview enable SourceControl <service>

• Automatically pushed to the mobile service

21

Serviceapi

sharedscheduler

tables

Page 19: Windows Azure Mobile Services - The Perfect Partner

node.js – Add your own modules

• Enable source control

• Go to ./service folder• npm install [module-name]• git add .• git commit –m “added stuff”

• Use in server scripts

22

serviceapinode_modules

sharedscheduler

tables

Page 20: Windows Azure Mobile Services - The Perfect Partner

Custom API

• HTTP request - GET, POST, PUT, PATCH, DELETEhttps://<service_name>.azure-mobile.net/api/<api_name>

• Request / response object implemented by express.js

More details at http://blogs.msdn.com/b/carlosfigueira/archive/2013/06/14/custom-apis-in-azure-mobile-services.aspx

23

exports.post = function(request, response) { // Use "request.service" to access features of your mobile service, e.g.: // var tables = request.service.tables; // var push = request.service.push;

response.send(200, "Hello World");

};

Page 21: Windows Azure Mobile Services - The Perfect Partner

Scheduled Jobs

• Scheduled or on-demand• Scenarios• Archive / Backup data (i.e. SQL Database)• Purge stale records (i.e. Push Notification

channels)• Query external systems and store locally• Whatever you can think of

• Initially disabled

24

Page 22: Windows Azure Mobile Services - The Perfect Partner

Application Settings

25

function sendEmail(item){ // alternative: process.env.SendGridUsername

var config = require('mobileservice-config'); var sendgrid = new SendGrid(config.appSettings.SendGridUsername, config.appSettings.SendGridPassword); sendgrid.send({ to: '[email protected]', from: '[email protected]', subject: 'You have work to do!!', text: 'A new task was added: ' + item },

exports.get = function (request, response) {    var config = request.service.config;    var isDebug = config.appSettings.isDebug === 'true';    if (isDebug) {        console.log('request url: ', request.url);        console.log('request headers: ', request.headers);        console.log('request query: ', request.query);    }

table operation custom API operation

Page 23: Windows Azure Mobile Services - The Perfect Partner

26

DEMO TIME!!!

Page 24: Windows Azure Mobile Services - The Perfect Partner

Push Notifications

3. M

PNS

send

s no

tice

to

devi

ce

2. App sends notice to

MPNS

1. Register channel with app

MicrosoftPushNotificationService

Mobile Services

Page 25: Windows Azure Mobile Services - The Perfect Partner

Push Notifications

Obtain Windows, Apple, or GCM push notification credentialsWindows: WNS client secret and package SID from Windows dev portal.Apple: Get a cert and create a profile from iOS Provisioning PortalGoogle: Get API key from Google API console

Enter appropriate notification credentials into the WAMS portal.

Ability to send Tile, Toast, Badge, and Raw notifications (Windows)

push.wns.* / push.apns.send (token, {alert, sound})Node.js module to create push notificationsHandles authentication against WNS, GCM, or APNS

Page 26: Windows Azure Mobile Services - The Perfect Partner

Notification Hubs

29

More information at http://msdn.microsoft.com/en-us/library/windowsazure/jj927170.aspx

May be ideal for working with multiple mobile clients.

Large number of clients & notifications.

Page 27: Windows Azure Mobile Services - The Perfect Partner

30

DEMO TIME!!!

Page 28: Windows Azure Mobile Services - The Perfect Partner

Authentication

Microsoft Account, Facebook, Twitter, and Google

Server-side / web-basedOAuthDoes not use Windows Azure ACS

Page 29: Windows Azure Mobile Services - The Perfect Partner

Authentication

Microsoft Account – Use the Live SDKTight integration with Windows Live services

Client side authentication

Facebook Android SDK info at http://blogs.msdn.com/b/carlosfigueira/archive/2014/01/08/using-the-facebook-android-sdk-for-logging-in-to-azure-mobile-services.aspx

Page 30: Windows Azure Mobile Services - The Perfect Partner

Authorization

Table & API authorizationEveryone: any request by anyone is accepted.Anyone with Application Key: app key distributed w/ the app (default)Authenticated Users: users that have been authenticatedScripts and Admins: registered scripts or requests via the master key

Your application can add whatever other authorization is needed.

Page 31: Windows Azure Mobile Services - The Perfect Partner

Authorization

Server script to match against your table (role-based access, specific user, etc.)Match against user.userId

Page 32: Windows Azure Mobile Services - The Perfect Partner

35

Preview Features

• Requires Windows Azure CLI tools• Once enabled, cannot be disabled

Page 33: Windows Azure Mobile Services - The Perfect Partner

36

DEMO TIME!!!

Page 34: Windows Azure Mobile Services - The Perfect Partner

Diagnostics

• API Calls• CPU Time• Data Out

Page 35: Windows Azure Mobile Services - The Perfect Partner

Developer Analytics / New Relic

38

• Add NewRelic via Windows Azure Store• Enable source control feature• npm install newrelic• Add and commit files

Page 36: Windows Azure Mobile Services - The Perfect Partner

Logging

console objectlog(formatString, obj, .. .)info(…)warn(…)error(…)

Page 37: Windows Azure Mobile Services - The Perfect Partner

Scale

Service Tier

CapacityAutoscaling rulesNumber of units

StorageManage SQL DB size

Page 38: Windows Azure Mobile Services - The Perfect Partner

Pricing and SLA

FREE 1 BASIC STANDARD

Price 2 Free(up to 10 services / month)

$25 / month per unit

$199 / month per unit

API Calls 2 500K 1.5M per unit 15M per unit

Active Devices 3 500 Unlimited Unlimited

Scale N/A Up to 6 units Up to 10 units

Scheduled jobs(Preview) 1 job, 1 execution per hour 10 jobs

50,000 executions10 jobs500,000 executions

SQL Database 5

(required)

20 MB included,Standard rates apply for additional capacity

20 MB included,Standard rates apply for additional capacity

20 MB included,Standard rates apply for additional capacity

SLA N/A 99.9% 99.9%

Suspension of Service

No admin action or user access for more than 90 days

30 days notice

N/A N/A

More details at http://www.windowsazure.com/en-us/pricing/details/mobile-services/

Page 39: Windows Azure Mobile Services - The Perfect Partner

Summary

Data

Notifications

Auth

Server Logic

Scheduling

Logging

Diagnostics

Page 40: Windows Azure Mobile Services - The Perfect Partner

Resources

• Windows Azure Mobile Services• http://aka.ms/mobileservices

• Mobile Services Concepts• http://msdn.microsoft.com/en-us/library/windowsazure/jj591475.aspx

• SDK and Samples available on GitHub• https://github.com/WindowsAzure/azure-mobile-services

• Inside Windows Azure Mobile Services• http://

channel9.msdn.com/posts/Kirill-Gavrylyuk-and-Josh-Twist-Inside-Windows-Azure-Mobile-Services

• Josh Twist’s Blog• http://www.thejoyofcode.com

• Carlos Figueira’s Blog• http://blogs.msdn.com/b/carlosfigueira/

Page 41: Windows Azure Mobile Services - The Perfect Partner

Q &

A

Ask your questions

Page 42: Windows Azure Mobile Services - The Perfect Partner

Thank You!

• Michael S. Collier• Principal Cloud Architect, Aditi

[email protected]• @MichaelCollier• www.MichaelSCollier.com

Next: “More Cache with Less Cash” – 1:45pm on Friday (Indigo Bay)