Windows Azure Mobile Services - The Perfect Partner

Preview:

Citation preview

Windows Azure Mobile Services: The Perfect Partner

Michael S. Collier@MichaelCollier

CodeMash – January 9, 2014

Michael S. Collier

• Principal Cloud Architect, Aditi

• michaelc@aditi.com• @MichaelCollier• www.MichaelSCollier.com

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

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

Agenda

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

• Q & A6

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

What is Windows Azure Mobile Services

Data

Notifications

Auth

Server Logic

Scheduling

Logging

Diagnostics

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

Client Support

Windows Phone Windows Store AndroidiOSHTML5Xamarin.iOSXamarin.AndroidSencha

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

12

DEMO TIME!!!

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

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) { });

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)

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

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

18

DEMO TIME!!!

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) {…..}

node.js

Known objects and modulesapnsazureconsolecryptogcmmpnsmssqlpushqueryrequestresponseservicesendgrid statusCodestableuserutil

var SendGrid = require('sendgrid').SendGrid;var sendgrid = new SendGrid(‘<account>', ‘<password>'); sendgrid.send({ to: userItem.EmailAddress, from: 'notifications@mytodoitem.azure-mobile.net', 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); } });

Source Control

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

• Automatically pushed to the mobile service

21

Serviceapi

sharedscheduler

tables

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

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

};

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

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: 'michael.collier@live.com', from: 'notifications@codemash-todo.azure-mobile.net', 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

26

DEMO TIME!!!

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

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

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.

30

DEMO TIME!!!

Authentication

Microsoft Account, Facebook, Twitter, and Google

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

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

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.

Authorization

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

35

Preview Features

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

36

DEMO TIME!!!

Diagnostics

• API Calls• CPU Time• Data Out

Developer Analytics / New Relic

38

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

Logging

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

Scale

Service Tier

CapacityAutoscaling rulesNumber of units

StorageManage SQL DB size

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/

Summary

Data

Notifications

Auth

Server Logic

Scheduling

Logging

Diagnostics

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/

Q &

A

Ask your questions

Thank You!

• Michael S. Collier• Principal Cloud Architect, Aditi

• michaelc@aditi.com• @MichaelCollier• www.MichaelSCollier.com

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

Recommended