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

Post on 26-Jan-2015

109 Views

Category:

Business

0 Downloads

Preview:

Click to see full reader

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

© 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

Session Goals • Cloud services, great apps • Apps today

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

AWS Mobile Landscape

AWS IAM

Social Login

Amazon S3

File Storage Amazon DynamoDB

User Data

Amazon SNS

Mobile Push

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

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

Web Identity Federation

Amazon S3

AWS IAM

Amazon DynamoDB

Web Identity Federation

S3 Transfer Manager

AWS Mobile SDKs

Geo Library for Amazon DynamoDB

Geo

Web Identity Auth Flow

AWS Cloud

Mobile Client

AWS STS

Amazon S3 Bucket

Access

${id}

Policy

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

S3 Transfer Manager

Amazon S3

AWS IAM

Amazon DynamoDB

Web Identity Federation

S3 Transfer Manager

AWS Mobile SDKs

Geo Library for Amazon DynamoDB

Geo

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

– Pictures – Videos – Music

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

Amazon S3 Transfer Manager – Demo

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

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];

}

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;

}

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];

Amazon S3 Transfer Manager • Learn More

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

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

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

Geo Library for Amazon DynamoDB Amazon DynamoDB

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

Geo

Geo Library for Amazon DynamoDB – Demo

• Picture Map from Mobile Photo Share

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

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

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;

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

AWS Mobile SDKs

Amazon S3

AWS IAM

Amazon DynamoDB

Web Identity Federation

S3 Transfer Manager

AWS Mobile SDKs

Geo Library for Amazon DynamoDB

Geo

AWS Mobile SDKs – Demo

• Favorite Pictures from Mobile Photo Share

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

AWS Mobile SDKs – Pattern Consistent usage pattern

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

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;

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];

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

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

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];

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

AWS Mobile • Mobile Development Center

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

• Get Help – Forum

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

– Stack Overflow

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

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

Please give us your feedback on this presentation

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

MBL402

top related