building cloud-backed mobile apps (mbl402) | aws re:invent 2013

37
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc. Building Cloud-backed Mobile Apps Glenn Dierkes, AWS Mobile November 13, 2013

Upload: amazon-web-services

Post on 26-Jan-2015

109 views

Category:

Business


0 download

DESCRIPTION

Connecting your mobile app to AWS can unlock powerful features. With AWS, you can streamline your sign-in experience with social login, store user data in the cloud and share it between devices, display location-specific information using geospatial queries, and engage your customers across multiple platforms with push notifications. In this session, you learn how to integrate these powerful features into a sample mobile app using Amazon DynamoDB, Amazon Simple Notification Service (Amazon SNS), and web identity federation.

TRANSCRIPT

Page 1: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc.

Building Cloud-backed Mobile Apps

Glenn Dierkes, AWS Mobile

November 13, 2013

Page 2: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Session Goals • Cloud services, great apps • Apps today

– Social Logins – Geo Tagging – File and Data Storage – Push Notifications

Page 3: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile Landscape

AWS IAM

Social Login

Amazon S3

File Storage Amazon DynamoDB

User Data

Amazon SNS

Mobile Push

Page 4: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Demo of the Mobile Photo Share sample App An app to share geo-tagged photos with others.

Page 5: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Mobile Photo Share – Architecture

Amazon S3

AWS IAM

Amazon DynamoDB

Web Identity Federation

S3 Transfer Manager

AWS Mobile SDKs

Geo Library for Amazon DynamoDB

Geo

Page 6: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Web Identity Federation

Amazon S3

AWS IAM

Amazon DynamoDB

Web Identity Federation

S3 Transfer Manager

AWS Mobile SDKs

Geo Library for Amazon DynamoDB

Geo

Page 7: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Web Identity Auth Flow

AWS Cloud

Mobile Client

AWS STS

Amazon S3 Bucket

Access

${id}

Policy

Page 8: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Web Identity Federation • Social Logins

– Managing Users is hard – Allow users to connect with their existing accounts.

• Facebook, Google, and Amazon. – Provides restricted temporary AWS Credentials

• Policy variables • Don’t put credentials in your app’s code (can’t rotate, not secure)

• Learn More – SEC401 session with Bob Kinney (Thursday 1:30 – 2:30 pm) – https://mobile.awsblog.com/post/Tx3UKF4SV4V0LV3

Page 9: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

S3 Transfer Manager

Amazon S3

AWS IAM

Amazon DynamoDB

Web Identity Federation

S3 Transfer Manager

AWS Mobile SDKs

Geo Library for Amazon DynamoDB

Geo

Page 10: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Amazon S3 Transfer Manager • Upload/Download files to/from Amazon S3

– Pictures – Videos – Music

• Pause, Resume, Cancel • Efficiency and failure tolerance • No backend

Page 11: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Amazon S3 Transfer Manager – Demo

• Upload Photo Page from Mobile Photo Share • View Photo Page from Mobile Photo Share

Page 12: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Amazon S3 Multipart Upload

-(void)multipartUpload:(NSData*)dataToUpload inBucket:(NSString*)bucket forKey:(NSString*)key

{

S3InitiateMultipartUploadRequest *initReq = [[S3InitiateMultipartUploadRequest alloc] initWithKey:key inBucket:bucket];

S3MultipartUpload *upload = [s3 initiateMultipartUpload:initReq].multipartUpload;

S3CompleteMultipartUploadRequest *compReq = [[S3CompleteMultipartUploadRequest alloc] initWithMultipartUpload:upload];

int numberOfParts = [self countParts:dataToUpload];

for ( int part = 0; part < numberOfParts; part++ ) {

NSData *dataForPart = [self getPart:part fromData:dataToUpload];

S3UploadPartRequest *upReq = [[S3UploadPartRequest alloc] initWithMultipartUpload:upload];

upReq.partNumber = ( part + 1 );

upReq.contentLength = [dataForPart length];

upReq.stream = stream;

S3UploadPartResponse *response = [s3 uploadPart:upReq];

[compReq addPartWithPartNumber:( part + 1 ) withETag:response.etag];

}

[s3 completeMultipartUpload:compReq];

}

Page 13: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Amazon S3 Multipart Upload (cont.) -(NSData*)getPart:(int)part fromData:(NSData*)fullData

{

NSRange range;

range.length = PART_SIZE;

range.location = part * PART_SIZE;

int maxByte = (part + 1) * PART_SIZE;

if ( [fullData length] < maxByte ) {

range.length = [fullData length] - range.location;

}

return [fullData subdataWithRange:range];

}

-(int)countParts:(NSData*)fullData

{

int q = (int)([fullData length] / PART_SIZE);

int r = (int)([fullData length] % PART_SIZE);

return ( r == 0 ) ? q : q + 1;

}

Page 14: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Amazon S3 Transfer Manager – Code // Creating the transfer manager

self.transferManager = [S3TransferManager new];

self.transferManager.s3 = s3client;

// Upload image

[self.transferManager uploadFile:fileName bucket:bucketName key:objectName];

// Download image

[self.transferManager downloadFile:fileName bucket:bucketName key:objectName];

// Pause, Resume, Cancel

[self.transferManager pauseAllTransfers];

[self.transferManager resumeAllTransfers];

[self.transferManager cancelAllTransfers];

Page 15: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Amazon S3 Transfer Manager • Learn More

– http://mobile.awsblog.com/post/TxIRFEQTW9XU8G – http://aws.amazon.com/mobile/

Page 16: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Geo Library for Amazon DynamoDB

Amazon S3

AWS IAM

Amazon DynamoDB

Web Identity Federation

S3 Transfer Manager

AWS Mobile SDKs

Geo Library for Amazon DynamoDB

Geo

Page 17: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Geo Library for Amazon DynamoDB • Java Library

– Produces geo-hash indexes for use with DynamoDB

• Used in a middle-tier – Helps to minimize client side networking and data manipulation

• Geo-tagged data – Example: Store Locator

Page 18: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Geo Library for Amazon DynamoDB Amazon DynamoDB

Geo Library for Amazon DynamoDB • getPoint • putPoint • deletePoint • queryRadius • queryRectangle

Geo

Page 19: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Geo Library for Amazon DynamoDB – Demo

• Picture Map from Mobile Photo Share

Page 20: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Geo Library for Amazon DynamoDB – Server Code // Setup the Amazon DynamoDB Client

AmazonDynamoDBClient ddb = new AmazonDynamoDBClient( credentials );

ddb.setRegion( Region.getRegion( Regions.fromName( "us-east-1" ) ) );

// Configure the GeoDataManager

GeoDataManagerConfiguration config = new GeoDataManagerConfiguration( ddb, "Photos" );

// Create the GeoDataManager

GeoDataManager geoDataManager = new GeoDataManager( config );

Page 21: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Geo Library for Amazon DynamoDB – Server Code // Requesting a geo-query server-side

GeoPoint centerPoint = new GeoPoint(requestObject.getDouble("lat"), requestObject.getDouble("lng"));

// Identify attributes to return from DynamoDB table

List<String> attributesToGet = new ArrayList<String>();

attributesToGet.add( “title” );

attributesToGet.add( “userId” );

QueryRadiusRequest request = new QueryRadiusRequest( centerPoint, 5000 );

request.getQueryRequest().setAttributesToGet( attributesToGet );

// Submit the request through the Geo Library

QueryRadiusResult queryRadiusResult = geoDataManager.queryRadius( queryRadiusRequest );

Page 22: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Geo Library for Amazon DynamoDB – Server Code // Analyzing the results

Map<String, AttributeValue> geoItems = geoQueryResult.getItem();

List<String> resultArray = new ArrayList<String>();

for (Map<String, AttributeValue> item : geoItems ) {

String userId = item.get( "userId” ).getS();

String title = item.get( “title” ).getS();

if ( filterUserId.equalsIgnoreCase( userId ) || title.startsWith( “public” ) ) {

resultArray.add( title );

}

}

return resultArray;

Page 23: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Geo Library for Amazon DynamoDB • Learn More Here

– https://github.com/awslabs/dynamodb-geo – http://mobile.awsblog.com/post/TxWTJOSLE7O3J2/

• Sample

– Provides an AWS Elastic Beanstalk middle tier – iOS App

Page 24: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile SDKs

Amazon S3

AWS IAM

Amazon DynamoDB

Web Identity Federation

S3 Transfer Manager

AWS Mobile SDKs

Geo Library for Amazon DynamoDB

Geo

Page 25: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile SDKs – Demo

• Favorite Pictures from Mobile Photo Share

Page 26: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile SDKs • Supports a number of AWS services

• Amazon DynamoDB, Amazon S3 • Amazon SQS, Amazon SNS, and more

• Fine-grained access control

• Segregates user data in DynamoDB

• Multiple Platforms • iOS • Android

Page 27: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile SDKs – Pattern Consistent usage pattern

• Create the service client • Create the request • Submit the request • Process the results

Page 28: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile SDKs – get favorites // Create the client AmazonDynamoDBClient *ddb = [[AmazonDynamoDBClient alloc] initWithCredentialsProvider:self.provider];

// Create the get request DynamoDBAttributeValue *userId = [[DynamoDBAttributeValue alloc] initWithS: [AmazonKeyChainWrapper userId]];

DynamoDBGetItemRequest *getItemRequest = [DynamoDBGetItemRequest new];

getItemRequest.tableName = DYNAMODB_TABLENAME;

getItemRequest.key = [NSMutableDictionary dictionaryWithObject:userId forKey:@"UserId"];

getItemRequest.consistentRead = YES;

// Submit the request DynamoDBGetItemResponse *getItemResponse = [ddb getItem:getItemRequest];

// Process the results DynamoDBAttributeValue *favorites = [getItemResponse.item valueForKey:@"Favorites"];

return favorites.sS;

Page 29: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile SDKs – put favorites // Create the put request DynamoDBPutItemRequest *putItemRequest = [DynamoDBPutItemRequest new];

putItemRequest.tableName = DYNAMODB_TABLENAME;

DynamoDBAttributeValue *userId = [DynamoDBAttributeValue new];

userId.s = theUserId;

DynamoDBAttributeValue *newFavorites = [DynamoDBAttributeValue new];

newFavorites.sS = theFavorites;

[putItemRequest.item setValue:userId forKey:@"UserId"];

[putItemRequest.item setValue:newFavorites forKey:@"Favorites"];

// Submit the request [ddb putItem:putItemRequest];

Page 30: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile SDKs

• Learn More Here – http://mobile.awsblog.com/post/Tx1U4RV2QI1MVWS/ – AWS SDK for Android

• http://aws.amazon.com/sdkforandroid – AWS SDK for iOS

• http://aws.amazon.com/sdkforios

Page 31: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

SNS Mobile Push • Push Notifications

– Single Topic – Push to users all platforms • Apple, Amazon, Google • Push to individual devices

– Console for easy setup

• Certificates • Keys

Page 32: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

SNS Mobile Push – Register Device Create a Platform Application

• Specify the support push notification service (APNS, GCM, etc.) • Console • Platform Application ARN

// Registering a device SNSCreatePlatformEndpointRequest *request = [SNSCreatePlatformEndpointRequest new];

request.customUserData = @"Here's the custom data for the user.";

request.token = deviceTokenString;

request.platformApplicationArn = @”The Platform Application ARN”;

[snsClient createPlatformEndpoint:request];

Page 33: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

SNS Mobile Push • Publish

– AWS Management Console – AWS SDKs

• Learn More Here

– http://aws.typepad.com/aws/2013/08/push-notifications-to-mobile-devices-using-amazon-sns.html

– http://docs.aws.amazon.com/sns/latest/dg/SNSMobilePush.html – MBL308 session (Friday 9:00 – 10:00 am)

• Engage Your Customers with Amazon SNS Mobile Push

Page 34: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile • Mobile Development Center

– http://aws.amazon.com/mobile

• Get Help – Forum

https://forums.aws.amazon.com/forum.jspa?forumID=88

– Stack Overflow

Page 35: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

AWS Mobile – Next Steps • Mobile Photo Share

– Server and iOS App – https://github.com/awslabs/reinvent2013-mobile-photo-share

• Other samples and SDKs

– https://github.com/awslabs/aws-sdk-android-samples – https://github.com/awslabs/aws-sdk-ios-samples

Page 36: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Connect • Booth & Office Hours

– Thursday 4:30 – 5:30 pm – Friday 9:00 – 10:00 am

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

• Twitter

– @awsformobile

Page 37: Building Cloud-Backed Mobile Apps (MBL402) | AWS re:Invent 2013

Please give us your feedback on this presentation

As a thank you, we will select prize winners daily for completed surveys!

MBL402