(gam401) build a serverless mobile game w/ cognito, lambda & dynamodb

58
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Dhruv Thukral, Amazon Web Services Solutions Architect, Gaming Tara E. Walker, AWS Technical Evangelist, Amazon Web Services October 2015 GAM 401 Serverless Mobile App and Game Development Build Your Game with Mobile Services

Upload: amazon-web-services

Post on 16-Apr-2017

3.953 views

Category:

Technology


2 download

TRANSCRIPT

© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Dhruv Thukral, Amazon Web Services Solutions Architect, Gaming

Tara E. Walker, AWS Technical Evangelist, Amazon Web Services

October 2015

GAM 401

Serverless Mobile App and Game DevelopmentBuild Your Game with Mobile Services

Before We Start

How Do You Build a Mobile

Game Today?

Authenticate usersManage users and identity providers

Authorize accessSecurely access cloud resources

Synchronize dataSync user preferences across devices

Store and deliver mediaStore DLC and deliver content quickly

Send real time eventsCreate live dashboards to track user events in real time

Analyze user behaviorTrack active users, engagement and stats

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

Send push notificationsBring users back to your app by sending messages reliably

Introducing AWS Mobile Services

Amazon Cognito Amazon Mobile Analytics Amazon SNS Mobile Push

Amazon Kinesis

Recorder

Amazon DynamoDB

Mapper

Amazon S3

Transfer Util

Amazon

SQS Client

Amazon SES

Client

Core building

block services

Mobile optimized

connectors

Mobile optimized

services

Your Mobile Game

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

Compute Storage Networking Analytics Databases

Integrated SDK

AWS Lambda

Lambda

Functions

λ λλλ

Authenticate usersManage users and identity providers

Authorize accessSecurely access cloud resources

Synchronize dataSync user preferences across devices

Store and deliver mediaStore DLC and deliver content quickly

Amazon Cognito

Sync

Amazon Cognito

Amazon Cognito

S3 Transfer

Utility

Send real time eventsCreate Live Dashboards to track user events in real time

Analyze user behaviorTrack active users, engagement and stats

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

Send push notificationsBring users back to your app by sending messages reliably

Kinesis

Recorder

DynamoDB

Mapper

Amazon

SNS Mobile Push

Amazon

Mobile Analytics

Authenticate users: Amazon Cognito

Amazon Cognito

Simplifies identity and

access management

Securely access all

AWS services from

mobile device

Cross-device and

cross-platform syncImplement 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

Amazon Cognito concepts

Identity pool

IAM roles, trust, and permissions

Identities: authenticated and unauthenticated

Getting started

Create an identity pool

Use SDK to get credentials

Create roles: authenticated and unauthenticated

Getting credentials

Include the following import statements

Initialize the Amazon Cognito credentials provider

Pass the initialized Amazon Cognito credentials provider to the constructor of

the AWS client to be used. This could be the Amazon Cognito Sync client,

the Amazon S3 transfer manager, or any of the other mobile services we will

talk about shortly.

End Users

App with

AWS Mobile

SDK

Access

to AWS

Services

Login OAUTH/OpenID

Access Token

Amazon

Cognito ID,

Temp

Credentials

Access

Token

Pool ID

Role ARNs

Amazon Cognito ID

(Temp Credentials)

DynamoDB

Developer

Amazon Cognito

Identity Broker

S3

Mobile Analytics

Amazon Cognito

Sync Store

AWS

Management

Console

Amazon Cognito security architecture

Amazon Cognito ID

(Temp Credentials)

End Users

Access

to AWS

Services

Get OpenID Token

User name,

password

Amazon

Cognito ID,

Temp

Credentials

OIDC Token

Pool ID

Role ARNs

User Authentication

System

(Running on AWS or not)

OIDC Token

OIDC Token

Developer authenticated identities

S3

Mobile AnalyticsAmazon Cognito

Identity Broker AWS

Management

Console

Developer

DynamoDB

Amazon Cognito

Sync Store

Synchronize data across devices : Amazon Cognito (Sync)

Amazon Cognito Sync

User data,

storage,

and sync

Any platform

iOS, 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

Integrating Amazon Cognito Sync functionality is simple

Import the Amazon Cognito package

Initialize the Sync client and use the previously created credentials provider

Datasets

Create a dataset or open an existing one

To delete a dataset

Reading and writing to a dataset

Removing keys from a dataset

Store and deliver media assets:

Amazon S3 and Amazon CloudFront

Amazon S3 Connector: Transfer Utility

S3 Connector

• Multipart upload (e.g., user content)

• Fault tolerant download (e.g., assets)

• No back end required

• Automatic retries

• Pause, resume, cancel functions

Integrating the S3 Transfer Utility is simple too!

Instantiate an Amazon S3 client

Instantiate TransferUtility

Performing operations

Upload an object

Download an object

Performing operations

Upload an object

Download an object

Tracking S3 transfer progress

Other operations

Pausing an S3 transfer

Resuming and S3 transfer

Cancelling an S3 transfer

Analyze user behavior: Amazon Mobile Analytics

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

Integrating Mobile Analytics is guess what….simple!

Initialize the MobileAnalyticsManager and that’s it….

We saw earlier where we can find our identity pool ID.

You can get the appid by creating a new app in the Mobile Analytics dashboard

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

Amazon Mobile Analytics dashboard

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

Custom event tracking using Mobile Analytics

Create an AnalyticsEvent, pass attributes and metrics

Then record the event

Send push notifications: Amazon SNS mobile push

Each platform works differently, and push gets more complex as

you scale to support millions of devices

Cloud app

Platform services Mobile apps

Amazon SNS

Cross-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 9 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

Store shared data: Amazon DynamoDB

Joe Anna Bob

Highscores

Joe 1500

Anna 800

Bob 750

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

Amazon DynamoDB Connector: Object Mapper

@DynamoDBTable(tableName = ”Highscores")

public static class HighScore{

private int userid, highScore;

private String name;

@DynamoDBHashKey(attributeName = ”userid")

public int getUserId() {

return userid;

}

public void setUserId(int userid) {

this.userid = userid;

}

@DynamoDBAttribute(attributeName=”name")

public String getName() {

return name;

}……

User ID Name High score

17 Joe 25

23 Anna 67

32 Bob 55

Table: high scores

Amazon DynamoDB mapper example

// Build a highscore object

HighScore highScore = new HighScore();

highScore.setUserId(17);

highScore.setName(”Joe");

highScore.setHighScore(25);

// Save book object to DynamoDB

mapper.save(highScore);

// Update item and save object again

highScore.setHighScore(118);

mapper.save(highScore);

// Load another highScore

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

Amazon DynamoDB mapper example

Quiz?

Q. What is the maximum number of datasets per identity in Amazon Cognito?

A. 20

Q. What object is returned by the TransferUtility when calling an upload or

download?

A. TransferObserver

Q. How many events can you store in the free tier for Mobile Analytics?

Q. 100 MM

Tappy Plane Architecture

and Demo

Now over to Tara!!

Tappy Plane architecture

Mobile Client

AWS Unity

SDK

AWS Toolkit for

Visual Studio

Amazon Cognito

Identity

AWS Cloud

DynamoDB

Mobile

Analytics

Amazno

Cognito Sync

Login

AWS Mobile SDKs for gaming

1. AWS Mobile SDK for Android

2. AWS Mobile SDK for iOS

3. AWS Mobile SDK for Unity (developer preview)

Introducing the AWS SDK for Unity

Generally available, May 2015

Services available

Amazon DynamoDB

Amazon S3

Amazon Cognito

Amazon Mobile Analytics

Amazon SNS

Other AWS services

Invoke Lambda with SNS and/or S3 events

Build custom plugins for other AWS services using

AWS Mobile SDK for.NET

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

Add the AWSPrefab to scene in Unity

Tappy Plane game

Game showcases

Amazon Cognito Identity

Amazon Cognito Sync

Mobile Analytics

Amazon S3 Transfer Utility

DynamoDB Mapper

Want More Game Samples?

AWS Unity SDK samples available on GitHub

https://github.com/awslabs/aws-sdk-unity-samples

Tappy Plane

AWS Mobile SDK: services setup

Tappy Plane : services setup

Set up Amazon Cognito identity pool

Create Tappy Plane identity pool

Retrieve identity pool ID

Set up Mobile Analytics app

Add Tappy Plane app

Retrieve app ID

Create Tappy Plane high score table

Create table

Add hash key

Add table attributes

Tappy Plane demo

Setting up AWS services in the console

Tappy Plane demo

Amazon Cognito: reviewing Unity3D code

Adding DynamoDB

Methods to 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: TappyHighScores

• Primary key type: Hash

• Hash attribute name: ScoreID,

• Hash type: Number

Create DynamoDB clientAmazonDynamoDBClient client = new

AmazonDynamoDBClient(RegionEndpoint.USEast1)

Using DynamoDB

Add a high score record

Create high score object

[DynamoDBTable(”TappyHighScores")]

class HighScore

{ [DynamoDBHashKey] // hash key

public int ScoreID { get; set; }

[DynamoDBProperty]

public string Score { get; set; }

public string UserID {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; }

High scores

Joe 1500

Anna 800

Bob 750

Adding Amazon Simple Storage Service (S3)

Methods create S3 bucket (set permissions)

Using Amazon 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: tappyplane_bucket

Create an Amazon S3 transfer managerAmazonS3Client S3Client =

new AmazonS3Client (credentials ,RegionEndpoint.USEast1);

Using Amazon 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 object

Upload a picture of high score

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

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

Thank you!

Serverless Mobile App and Game Development

Build your game with Mobile Services

Tara Walker AWS Technical Evangelist, Amazon Web Services

Dhruv Thukral Amazon Web Services Solutions Architect, Gaming

Remember to complete

your evaluations!

Related Sessions