serverless geospatial mobile apps with aws

Post on 14-Apr-2017

1.444 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

Serverless Geospatial Mobile Apps with Amazon Web Services

Olivier Klein, Solutions Architect, Amazon Web Services, Greater China

AWS Lambda

COMPUTE SERVICE

EVENT DRIVEN

Run code at any

scale without

thinking about

servers

Code only runs

when it needs to

run, charged on

execution time

AWS Lambda: Putting it to work

… and the list will

continue to grow!

Amazon Echo

skills

File processing

with Amazon S3

Amazon

Dynamo DB

triggers

Amazon

Kinesis

processors

Microservices

with API

Gateway

AWS

CloudFormation

custom

resources

Customized

notifications with

Amazon SNS

Amazon Cognito

triggers

Mobile and

Web backends

Amazon Cognito

Authenticate & sync

Amazon Mobile Analytics

Analyze user behavior

AWS Lambda

Run business logic

Amazon S3

Amazon DynamoDB

Store content

Store data

Amazon SNS mobile push

notifications

Send push notifications

Back end architecture on AWS

Mobile SDK

Amazon API Gateway

Sample app: “Find-a-Like”

• Premise: Create a profile with interests

and get notified when like-minded users

are nearby

• Functionalities:

• Create a profile with interests and upload

content

• Track location continuously

• Notify when users with similar interests are

close by

• Log and analyze app usage

Let’s think in layers

Create profile, upload

content, and track usage

Track location and user

interests

Match and alert users

App-centric

“You”

Activity-centric

“What you do”

User base-centric

“Them & me”

1

2

3

Create a profile, upload content,

and track usage

1

Cognito

Mobile Analytics

SNS Mobile Push

Kinesis Recorder DynamoDB Mapper S3 Transfer Manager

SQS Client

AWS global infrastructure (regions, Availability Zones, edge locations)

Core building

block services

Mobile-optimized

connectors

Your mobile app

AWS Mobile SDK (iOS, Android, Unity, Xamarin)

Compute Storage Networking Analytics Databases

Integrated SDK

Lambda

AWS Mobile SDKs

Security model for AWS API calls

Mobile client

IAM PermissionsAWS Security

Token Service

1. Request token

2. Receive temporary

credentials

3. Sign API request

with temporary token

AWS service APIs

4. Make API request

against AWS service API

Authenticate your user: Amazon Cognito

• Generate temporary credentials

and enforce rotation to limit

credential lifetime

• Authenticate user through third-party

authentication provider

• Unique users across multiple

devices and identity providers

• Allows anonymous user access

• Enables security best practices

through IAM roles

Create your profile: Cognito Sync

• Create your app profile and save it

locally in the Cognito data store

• Cognito will synchronize the data sets

across all your user’s devices

• Cognito data sets are key/value pairs

AWSCognito *syncClient = [AWSCognito defaultCognito];

AWSCognitoDataset *subs = [syncClientopenOrCreateDataset:@”UserProfile"];

[dataset setString:”Oli" forKey:@”name"];[dataset setString:”50km" forKey:@”interestRadius"];

[dataset synchronize];

Upload a profile picture: S3 Transfer Utility

• Amazon S3 to store and share UGC

directly from the mobile device

• S3 Transfer Utility provides:

• Ability to continue transferring data in

the background when your app is

not running

• Ability to upload binary data instead

of having to first save it as a file on

the device

Amazon S3

S3 Transfer Utility: iOS code

NSData *dataToUpload = // The data to upload

AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];

[[transferUtility uploadData:dataToUpload

bucket:@"YourBucketName"

key:@"YourObjectKeyName"

contentType:@"text/plain"

expression:expression

completionHander:completionHandler] continueWithBlock:^id(AWSTask *task) {

if (task.result) {

AWSS3TransferUtilityUploadTask *uploadTask = task.result;

// Do something with uploadTask

}

}

Track app usage: Amazon Mobile Analytics

• Allows you to collect, visualize, and

understand your mobile app usage

• Scales seamlessly to billions of events

per day

• You retain full control and ownership

of the data

Amazon Mobile

Analytics

AWSMobileAnalytics *analytics = [AWSMobileAnalytics

mobileAnalyticsForAppId:@"yourAppId” identityPoolId: @"cognitoId"];

User Retention: Bubble Island

User Retention: Bubble Island

Daily active users

(DAU) dropped,

but why?

Level Progression (One Metric)

0

2

4

6

8

10

L1 L2 L3 L4 L5 L6 L7 L8 L9 L10

Tries / Level

# of Tries

Level Progression (Two Metrics)

0

10

20

30

40

50

60

0

2

4

6

8

10

L1 L2 L3 L4 L5 L6 L7 L8 L9 L10

Tries / Level

% Highest Level # of Tries

User Retention: Bubble Island

User Retention: Bubble Island

Let’s think in layers

Create profile, upload

content, and track usage

Track location and user

interests

Match and alert users

App-centric

“You”

Activity-centric

“What you do”

User base-centric

“Them & me”

1

2

3

Track location and user interests

2

How to collect location and interests?

Back-end logic DatabaseMobile

“Location Tracker” and “Interest” microservice

Amazon

Lambda

Amazon API

Gateway

Amazon

DynamoDB

• /location

• /interests

• reportLocation()

• likeInterest()

• createInterest()

• listInterest()

Microservice

• location-table

• interest-table

Concepts first: Geohash

GeoHash is a lat/long

geocode system that

subdivides space into

buckets on a grid.

Can be numerical

e.g.6093522776912656819

Divide the planet earth

into six cells

(A,B,C,D,E,F) like the

six faces of a cube.

Divide each cell into

child cells, and divide

child cells into more

child cells. The red dot

here would thus be

A224.

Works with

DynamoDB!

How does it work?

Geo library for Amazon DynamoDB

• Java library to easily create and query

geospatial data in DynamoDB using GeoHashes

GeoPoint point = new GeoPoint(47.62, -122.34);

// find places 250m of Seattle’s Space NeedleQueryRadiusRequest request = new

QueryRadiusRequest(point, 250);

QueryRadiusResult result = geoDataManager.queryRadius(request);

https://github.com/awslabs/dynamodb-geo

Works with

Lambda!

Amazon API Gateway

• Fully managed and scalable RESTful

API gateway service

• Powered through our content

delivery network via our 53 global

edge locations

• Provides DDoS protection and

throttling capabilities

• Multiple API stages which you define

(e.g. dev, test, prod)

AWS Lambda

Amazon API

Gateway

Amazon

EC2

AWS API

On-prem

server

When to choose API Gateway vs. Direct SDK?

• Amazon API Gateway adds an additional layer

between your mobile users and your logic and

data stores in order to:

• Allow back-end logic to be interchanged without

mobile app code modifications

• Ability to throttle individual users or requests

• Protect against DDoS attacks including

counterfeit requests (Layer 7) and SYN floods

(Layer 3)

• Provide a caching layer for your calls

• Enables CORS for all AWS service for web apps

Let’s think in layers

Create profile, upload

content, and track usage

Track location and user

interests

Match and alert users

App-centric

“You”

Activity-centric

“What you do”

User base-centric

“Them & me”

1

2

3

Match and alert users

3

DynamoDB

streams

Cognito

Sync trigger

S3 event

notification

AWS Lambda: Event-driven compute

Find a proximity match based on interests

/location

REST API

Profile

(proximity

setting)

Interest table

AWS SDK call

reportLocation()

Invoke

findMatch()

DynamoDB Streams

GeoHash table

AWS SDK call

Interest tablelikeInterest()

/interest

DynamoDB Streams processor: findMatch()

exports.handler = function(event, context) {

// Process all the records in the stream

event.Records.forEach(function(record) {

var newLocation = record.dynamodb.NewImage.geohash.S;

if (findProximityMatch(newLocation)) {

// Found match!

}

});

context.succeed();

};

We found a match. Now what?

Amazon SNS mobile push notifications

• Amazon SNS is a fully

managed, cross-platform

mobile push intermediary

service

• Fully scalable to millions

of devices

• Allows you to create

topics (e.g. per geo,

interest, usage pattern,

etc.)

Amazon SNS

Apple APNS

Google GCM

Amazon ADM

Windows WNS and

MPNS

Baidu CP

Android phones and tablets

Apple iPhones and iPads

Kindle Fire devices

Android phones and tablets in China

iOS

Windows phone devices

Amazon

SNS

Found a match: Notify user!

AWS SDK call

findMatch()

DynamoDB Streams

GeoHash table

Interest table

Amazon SNS

But what if I adjust my profile?

Interest Radius

Cognito Sync Trigger – AWS Lambda Code

exports.handler = function(event, context) {

if (event.eventType === 'SyncTrigger') {

event.datasetRecords.forEach(function(item) {

if (item.interestRadius.op == 'replace') {

// New interest radius set - process findMatch()

var params = {

FunctionName: 'findMatch',

InvocationType: 'Event', //makes it async

Payload: '{"user":'+ item.identityId +'}’};

lambda.invoke(params, function(err, data) {[..]});

}

}

}

context.succeed(event);

};

Let’s think in Layers

Create profile, upload

content and track usage

Track location and user

interests

Match and alert users

App Centric

“You”

Activity Centric

“What You Do”

User Base Centric

“Them & Me”

1

2

3

Mobile AppMobile

SDKAmazon

API

Gateway

AWS

Lambda

Amazon

S3

Amazon

DynamoDB

Amazon

Cognito

Amazon Mobile

Analytics

Amazon

SNS

Final architecture

Thank you!

Olivier Klein 奧樂凱Solutions Architect, Greater China

top related