build & deploy your mobile game with aws by dhruv thukral and tara walker

47
1 Build & Deploy Your Mobile Game with AWS Dhruv Thukral Solutions Architect, Gaming [email protected] Tara Walker Technical Evangelist [email protected]

Upload: amazon-web-services

Post on 21-Aug-2015

472 views

Category:

Mobile


4 download

TRANSCRIPT

Page 1: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

1

Build & Deploy Your Mobile Game with AWS

Dhruv ThukralSolutions Architect, Gaming

[email protected]

Tara WalkerTechnical Evangelist

[email protected]

Page 2: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Not just about the Mobile Game anymore!

Page 3: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Authenticate users

Authorize access

Synchronize data

Manage users and identity providers

Securely access cloud resources

Sync user preferences across devices

Store and Deliver media

Send Push Notifications

Store user-generated photos Media and share them

Bring users back to your app by sending messages reliably

Store shared dataStore and query fast NoSQL data across users and devices

Analyze User BehaviorTrack active users, engagement

Page 4: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Introducing AWS Mobile Services

Amazon Cognito Amazon Mobile Analytics Amazon SNS Mobile Push

Kinesis Recorder DynamoDB Mapper S3 Transfer Mgr SQS Client SES Client

Core Building Block Services

Mobile Optimized Connectors

Mobile Optimized Services

Your Mobile Game

AWS Mobile SDK for iOS, Android & Unity, API Endpoints, Management Console

Compute Storage Networking Analytics Databases

Integrated SDK

AWS Lambda

Lambda Functions

λ λλλ

Page 5: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Authenticate users: Amazon Cognito

Page 6: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon Cognito

Simplifies Identity and Access Management

Securely access all AWS services from

Mobile device

Cross-device and Cross-platform Sync

Implement security best practices

“Your App data is secure, available offline, and kept in sync between devices”

Synchronize user’s data across devices and

platforms

Manage users as unique identities across

identity providers

Guest Your own Auth

Page 7: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Getting Started with Cognito in 3 steps

Sign up for AWS Account and login to AWS Management Console

Download and integrate the Mobile SDK and store and sync user data in a dataset

Create an identitypool for authenticated and unauthenticated users in the AWS Console

Page 8: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon Cognito Security

Set granular access permissions on AWS resources

Safeguard AWS Credentials

Helps implement security best practices

EC2 S3 DynamoDB Kinesis

Page 9: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon Cognito Security Architecture

End Users

App with AWS Mobile

SDK

Accessto AWS

Services

Login OAUTH/OpenIDAccess Token

Cognito ID, Temp

Credentials

Access TokenPool ID

Role ARNs

Cognito ID(Temp

Credentials)

DynamoDB

Developer

Cognito Identity Broker

S3

Mobile Analytics

Cognito Sync Store

AWS Management

Console

Page 10: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Developer Authenticated Identities

Cognito ID(Temp

Credentials)

DynamoDB

End Users

Developer

Accessto AWS

Services

Cognito Identity Broker

Get OpenID Token

Username password

Cognito ID, Temp Credentials

S3

Mobile Analytics

Cognito Sync Store

AWS Management

Console

OIDC TokenPool ID

Role ARNs

User Authentication System

(Running on AWS or not)

OIDC Token

OIDC Token

Page 11: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Synchronize data across devices : Amazon Cognito (Sync)

Page 12: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon Cognito Sync

User Data Storage andSync

Any PlatformiOS/Android/FireOS

Store App Data, Preferences and StateSave app and device data to the cloud and merge them after login

Cross-device Cross-OS Sync Sync user data and preferences across devices with one line of code

Work OfflineData always stored in local SQLite DB first. Works seamlessly when intermittent or no connectivity

k/v data

Identity pool

Page 13: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Integrating Cognito Sync functionality is simple

Initialize the CredentialsProvider and CognitoClient

Call synchronize on the dataset

Create or open Dataset and Add Key Values

CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider( getApplicationContext(), "IDENTITY_POOL_ID”, Regions.US_EAST_1);

CognitoSyncManager client = new CognitoSyncManager( getApplicationContext(), Regions.YOUR_REGION, credentialsProvider);

dataset.synchronize(syncCallback);

client.openOrCreateDataset(datasetName);dataset.put(key, value);

Page 14: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Integrating Cognito Sync functionality is simple

Initialize the AWSCognitoSyncClient

Call synchronize on the dataset

Create or open Dataset and Add Key Values

AWSCognitoDataset *dataset = [syncClient openOrCreateDataset:@"myDataSet"];[dataset setString:@"my value" forKey:@"myKey"]; NSString *value = [dataset stringForKey:@"myKey"];

AWSCognito *syncClient = [AWSCognito defaultCognito];

[dataset synchronize];

iOS

Page 15: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Store and deliver media assets: Amazon S3 and CloudFront

Page 16: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon S3 Connector: Transfer Manager

S3 Connector

Multipart upload media (photos, videos, audio)Fault tolerant download (e.g. assets)No backend requiredAutomatic retriesPause, resume, cancel functions

Page 17: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

// Creating the transfer manager

AmazonS3 s3 = new AmazonS3Client(credentialsProvider);

s3.setRegion(Region.getRegion(Regions.MY_BUCKET_REGION));

TransferUtility transferUtility = new TransferUtility(s3, APPLICATION_CONTEXT);

// Upload file

TransferObserver observer = transferUtility.upload( MY_BUCKET, OBJECT_KEY,

MY_FILE);

// Download file

TransferObserver observer = transferUtility.download( MY_BUCKET, OBJECT_KEY,

MY_FILE);

// Pause, Resume, Cancel

transferUtility.pause(idOfTransferToBePaused);

transferUtility.resume(idOfTransferToBeResumed);

transferUtility.cancel(idToBeCancelled);

Amazon S3 Connector: Transfer Manager

Page 18: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

// Creating the transfer manager

AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];

// Download file

AWSS3TransferManagerDownloadRequest *downloadRequest = [AWSS3TransferManagerDownloadRequest

new];

downloadRequest.bucket = @"myBucket";

downloadRequest.key = @"myImage.jpg";

downloadRequest.downloadingFileURL = downloadingFileURL;

// Upload File

AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];

// Pause and Resume File Download

[downloadRequest pause]; [transferManager download:downloadRequest];

Amazon S3 Connector: Transfer Manager

Page 19: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Analyze User Behavior: Amazon Mobile Analytics

Page 20: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon Mobile Analytics

Scalable and Generous Free Tier

Focus on metrics that matter. Usage reports available within 60 minutes of

receiving data from an app

Fast

Scale to billions of events per day from

millions of users.

Own Your Data

“Easily collect, visualize and understand your app usage data at scale”

Data collected are not shared, aggregated, or

reused

Page 21: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Getting Started with Mobile Analytics in 3 steps

Sign up for AWS Account and create or use existing Cognito ID in the AWS Management Console

View engagement and session activity reports in the AWS Management console within minutes

Download and integrate the Mobile SDK with one line of code (Android/FireOS, iOS)

Page 22: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Key Business Metrics (with one line of code) 1. Monthly Active Users

(MAU) 2. Daily Active Users

(DAU) 3. New Users, 4. Daily Sessions, 5. Sticky Factor, 6. 1-Day Retention, 7. Avg. Revenue per DAU, 8. Daily Paying Users,9. Avg. Paying DAU

Page 23: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Get behavioral insights into app specific actions that your users take

Reports provide a view of how often custom events occur. You can add further context with Attributes and Metrics, to each custom event

Track the number of Likes/Shares, per article, in a news app

Understand player abort rates per level, in a game

Number of songs played, per user session, in a music app

In-app item popularity in a shopping app

Track Custom Events

Page 24: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Integrating Mobile Analytics is simple

Initialize the MobileAnalyticsManager. That’s it!

For Custom Events activity reports, add events.

Add OnResume() and OnPause()

private static MobileAnalyticsManager analytics;analytics = MobileAnalyticsManager.getOrCreateInstance (this.getApplicationContext(), "appId", "identityPoolId”);

EventClient eventClient = analytics.getEventClient();MobileAnalyticsEvent levelCompleteEvent=eventClient.createEvent("LevelComplete");eventClient.recordEvent(levelCompleteEvent);

analytics.getSessionClient().resumeSession();analytics.getSessionClient().pauseSession();analytics.getEventClient().submitEvents();

Page 25: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Integrating Mobile Analytics is simple

Initialize the AWSMobileAnalytics object. That’s it!

Submit the event. If we don't call submitEvents, events will automatically be submitted at periodic intervals.

Create add Custom Events

[eventClient submitEvents];

id<AWSMobileAnalyticsEventClient> eventClient = analytics.eventClient;id<AWSMobileAnalyticsEvent> levelEvent = [eventClient createEventWithEventType:@"LevelComplete"];

AWSMobileAnalytics *analytics = [AWSMobileAnalytics mobileAnalyticsForAppId:@"yourAppId" identityPoolId: @"cognitoId"];

iOS

Page 26: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Send Push Notifications: Amazon SNS Mobile Push

Page 27: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Each platform works differently, and push gets more complex as you scale to support millions of devices.

Cloud App

Platform Services Mobile Apps

Page 28: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon SNSCross-

platform Mobile Push

Internet

Apple APNS

Google GCM

Amazon ADM

Windows WNS and MPNS

Baidu CP

New features:

Message Expiry TimeMessage Attributes

Delivery StatusBroadcast

iOS 8 support.

Amazon SNS Mobile Push

Android Phones and Tablets

Apple iPhones and iPads

Kindle Fire Devices

Android Phones and Tablets in China

iOS

Windows Desktop and Windows Phone Devices

Page 29: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Store Shared Data: Amazon DynamoDB

Page 30: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Joe Anna Bob

Highscores

Joe 1500

Anna 800

Bob 750

Amazon DynamoDB Connector: Object Mapper

Simplifies access to Amazon DynamoDB in your app

Map client-side classes to Amazon DynamoDB tables

Removes the need to transform objects into tables and vice versa

Page 31: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon DynamoDB: Example@DynamoDBTable(tableName = ”Highscores")

public static class HighScore{

private int id, highScore;

private String name;

@DynamoDBHashKey(attributeName = "id")

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

@DynamoDBAttribute(attributeName=”name")

public String getName() {

return name;

}……

id name highscore

17 Joe 25

23 Anna 67

32 Bob 55

Table: Highscores

Page 32: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Amazon DynamoDB: Example// Build a highscore object

HighScore highScore = new HighScore();

highScore.setId(17);

highScore.setName(”Joe");

highScore.setHighScore(25);

// Save book object to dynmaoDB

mapper.save(highScore);

// Update item and save object again

highScore.setHighScore(118);

mapper.save(highScore);

// Load another book

HighScore anotherHighScore = mapper.load(HighScore.class,23);

Page 33: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Some Best Practices for Backend Services

S3: • How you name your S3 Objects is very Important.• Randomize the prefix of your object keys to ensure better distribution on

S3’s partitions.• You don’t have to worry about the bucket name itself.• If your app is GET heavy on S3 Objects, consider using CloudFront

DynamoDB:• Keep item size small• Store metadata in Amazon DynamoDB and large blobs in Amazon S3 • Avoid hot keys and hot partitions• Use conditional/OCC updates

Page 34: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Now over to Tara!!

Page 35: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

AWS Mobile SDKs for Gaming

1. AWS Mobile SDK for Android2. AWS Mobile SDK for iOS3. AWS Mobile SDK for Xamarin (New - Dev Preview)4. AWS Mobile SDK for Unity

Page 36: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Introducing the AWS SDK for Unity

• Generally Available as of May 2015• Services available

Amazon DynamoDB Amazon S3 Amazon Cognito Amazon Mobile Analytics Amazon SNS

• Kick off AWS Lambda with SNS and/or S3

• Can build custom plugins with AWS .NET SDK if desired

Page 37: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

SDK Installation and Setup

• Download AWS Unity SDK and unzip– http://aws.amazon.com/mobile/sdk/

• Import the desired package(s) into Unity as a Custom Package– CognitoSync Package– DynamoDB Package– S3 Package– MobileAnalytics Package– SNS Package

• Add the AWSPrefab to Scene in Unity

Page 38: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Grumpy Flappy Game

• Demo will showcase– Cognito Identity– Cognito Sync– Mobile Analytics

• Similar Demos will be open-sourced …and polished– Showing more of the AWS services

• Other Unity Samples Available on GitHub

Page 39: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Grumpy Flappy Demo

AWS Mobile SDK: Services Setup

Page 40: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Grumpy Flappy : Services Setup

• Set up Cognito Identity Pool– Create Grumpy Flappy Identity Pool– Retrieve Identity Pool ID

• Set up Mobile Analytics App– Add Grumpy Flappy App– Retrieve App ID

Page 41: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Grumpy Flappy Demo

Amazon Cognito: Unity3D Code

Page 42: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Adding DynamoDB

• Create DynamoDB Table– Using DynamoDB Console– Using code with createTable method– Using Visual Studio with AWS Toolkit for Visual Studio:

http://aws.amazon.com/net/ – Example:

• Table Name: GrumpyScoreTable • Primary Key Type: Hash• Hash Attribute Name: PlayerID, • Hash Type: Number

• Create DynamoDB ClientAmazonDynamoDBClient client = new AmazonDynamoDBClient(RegionEndpoint.USEast1)

Page 43: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Using DynamoDB• Add a High Score Record

– Create High Score Object[DynamoDBTable("GrumpyScoreTable")]class FlappyScoreData{ [DynamoDBHashKey] // hash key public int PlayerID { get; set; } [DynamoDBProperty] public int LastScore { get; set; } [DynamoDBProperty]

public int HighScore {get; set; }}

– Save High Score Record to DynamoDB_context.SaveAsync<HighScore>(myScore, (AmazonDynamoResult<VoidResponse> result) =>

{ if (result.Exception != null) { this.displayMessage += "Save failed ; “ +result.Exception.Message; }

Page 44: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Adding Simple Storage Service (S3)

• Create S3 Bucket (set permissions)– Using S3 Console– Using code with PutBucket and PutBucketRequest– Using Visual Studio with AWS Toolkit for Visual Studio:

http://aws.amazon.com/net/ – Example:

• Bucket Name: grumpyflappy_bucket

• Create an S3 Transfer ManagerAmazonS3Client S3Client =

new AmazonS3Client (credentials ,RegionEndpoint.USEast1);

Page 45: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

Using Simple Storage Service (S3)• Download an Object

– Get Badge Picture (bragging rights)var request = new GetObjectRequest (){ BucketName = bucketName, Key = downloadKey,};S3Client.GetObjectAsync (request, GetObjectCallback,null);

• Upload an ObjectStream stream = null;stream = new FileStream(uploadSrcFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);var postRequest = new PostObjectRequest{ Key = uploadKey, Bucket = bucketName, InputStream = stream };S3Client.PostObjectAsync (postRequest, PostObjectCallback,null);

Page 46: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

AWS Gaming Solutions

AWS Resources

• AWS Mobile Blog– http://mobile.awsblog.com

• AWS Mobile Services– http://aws.amazon.com/mobile/

• AWS Mobile SDK– http://aws.amazon.com/mobile/sdk/

• AWS Mobile Developer Guides– Unity: http://docs.aws.amazon.com/mobile/sdkforunity/developerguide– iOS: http://docs.aws.amazon.com/mobile/sdkforios/developerguide – Android: http://

docs.aws.amazon.com/mobile/sdkforandroid/developerguide/Welcome.html

Page 47: Build & Deploy Your Mobile Game with AWS by Dhruv Thukral and Tara Walker

47

Fill out feedback survey and win:

bit.ly/connectaws