Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Build Mobile Apps using AWS SDKs and AWS Mobile Hub

1,974 views

Published on

Mobile Apps are increasingly popular these days to deliver efficient and cost-effective ways to interact with your end consumers. Amazon Web Services offers a number of services that help you to easily launch apps in the cloud, scale them cost-effectively and deliver them to your global customer base. This session will cover our native mobile app services like AWS Mobile Analytics, Amazon Cognito, Amazon SNS or AWS Device Farm, including the SDKs for iOS and Android. It will also demonstrate how to create fully managed and scalable applications using AWS Lambda, our new compute service that runs your code in response to events and manages compute resources for you, in conjunction with Amazon API Gateway that acts as a “front door” for applications to access data, business logic, or functionality from your back-end services. Lastly, it will cover how the new AWS Mobile Hub can help you develop your mobile apps even faster.

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

Published in: Technology
  • There are over 16,000 woodworking plans that comes with step-by-step instructions and detailed photos, Click here to take a look ◆◆◆ http://tinyurl.com/y3hc8gpw
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Build Mobile Apps using AWS SDKs and AWS Mobile Hub

  1. 1. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Olivier Klein 奧樂凱 Solutions Architect, Greater China April 2016 Build Mobile Apps using AWS SDKs and Mobile Hub
  2. 2. Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications Manage users and identity providers and sync prefs across devices Securely access cloud resources Test across multiple devices and operating systems Track active users, engagement Run stateless custom code without servers Store user-generated content and share it Deliver content quickly globally Bring users back to your app by sending messages reliably Store and query fast NoSQL data across users and devices Collect real-time event logs and take actions quickly
  3. 3. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  4. 4. SDKs Java Python (boto) PHP .NET Ruby Node.js iOS Android Go JavaScript C++
  5. 5. OK let’s build an App!
  6. 6. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  7. 7. • Authenticates your users • Facebook, Google, Amazon,Twitter, OpenID • Anonymous • Manages the users and synchronize data across multiple devices • Allows secure communication with other AWS services Amazon Cognito Amazon Cognito
  8. 8. Initialize the Cognito Client CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider( myActivity.getContext(), // get the context for the current activity "AWS_ACCOUNT_ID", "COGNITO_IDENTITY_POOL_ID", "arn:aws:iam::AWS_ACCOUNT_ID:role/UNAUTHENTICATED_ROLE", "arn:aws:iam::AWS_ACCOUNT_ID:role/AUTHENTICATED_ROLE", Regions.US_EAST_1 ); // Create a service client with the provider AmazonDynamoDB client = new AmazonDynamoDBClient(cognitoProvider);
  9. 9. Store and Synchronize Data CognitoSyncManager syncClient = new CognitoSyncManager(myActivity.getContext(), COGNITO_POOL_ID, Regions.YOUR_REGION, cognitoProvider); Dataset dataset = client.openOrCreateDataset("myDataset"); dataset.put("myKey", "my value"); String value = dataset.get("myKey"); dataset.remove("myKey"); dataset.synchronizeOnConnectivity(this, syncCallback);
  10. 10. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  11. 11. Control access to your AWS resources • Create users, groups or roles • Fine grained control access control with IAM policies • Control who can do what from where • Permit resource access social identities • Easily add multi factor authentication using hardware tokens or smartphone apps Identity and Access Management (IAM)
  12. 12. { "Effect":"Allow", "Action":["s3:*"], "Resource":"*" } { "Effect": "Allow", "Action": ["cognito-sync:*"], "Resource": "*" } { "Effect": "Deny", "Action": ["dynamodb:*"], "Resource": "*" } Allow Actions: All S3 Sync store Operations Resource: All resources within these services Deny Actions: All DDB Operations Resource: All resources Access Policy for IAM Role
  13. 13. Allow Actions: S3 Get/Put operations Resource: Only to a specific part of bucket to that identity { "Effect": "Allow”, "Action": ["s3:GetObject","s3:PutObject"], "Resource": ["arn:aws:s3::: myBucket/amazon/myapp/${cognito-identity.amazonaws.com:sub}"] } Allow Actions: DDB Get/Put operations Resource: Only to a specific cells in the database { "Effect": "Allow”, "Action": ["dynamodb:GetItem", "dynamodb:PutItem"], "Resource" : [ "arn:aws:dynamodb:REGION:12345:table/TABLE_NAME”], "Condition": { "ForAllValues:StringEquals”:{ "dynamodb:LeadingKeys": ["${cognito-identity.amazonaws.com:sub}"], "dynamodb:Attributes”: ["Wins","Losses”,"TopScore",”DateTime" ] }, } Access Policy Restriction (Policy Variables)
  14. 14. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  15. 15. AWS Device Farm • Test your app on real devices in the AWS cloud • Fully managed and scalable test platform • Many different smartphone and tablet models available • Full built-in test suite • Integration with custom frameworks (e.g. Appium, Calabash etc.) AWS Device Farm
  16. 16. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  17. 17. Amazon Mobile Analytics • Allows 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
  18. 18. Get insights into app specific actions that your users take Examples Track the number of Likes/Shares in a news app Player abort rates per level in a game Number of songs playedin a music app In-app purchase item popularity Custom Events
  19. 19. Initialize Mobile Analytics // Within your activity private static MobileAnalyticsManager analytics; // Within your activity onCreate() try { AnalyticsConfig options = new AnalyticsConfig(); options.withAllowsWANDelivery(true); analytics = MobileAnalyticsManager.getOrCreateInstance( getApplicationContext(), "YOU MOBILE ANALYTICS APP ID", Regions.US_EAST_1, cognitoProvider ); } catch(InitializationException ex) { Log.e(this.getClass().getName(), "Failed to initialize Mobile Analytics", ex); }
  20. 20. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  21. 21. AWS Lambda • Run your code in the cloud, fully managed and highly-available • Triggered through API calls or state changes in your setup (S3, DynamoDB, SNS, Kinesis) • Scales automatically to match the incoming event rate • Charged per 100ms execution time Amazon Kinesis Amazon Lambda Amazon S3 Amazon DynamoDB Amazon API Gateway Amazon SNS
  22. 22. Adding a Lambda Backend to your App Initialize the LambdaFactory and define the Interface for the functions Call synchronize on the dataset Create the Lambda Function lambda = new LambdaInvokerFactory(context, Regions.US_WEST_2, provider); //interface @LambdaFunction(functionName="cloudFunction”) String localFunction(String nameInfo); lambda.localFunction(“Hello From “); // this will output “Hello From Lambda” exports.handler = function(event, context) { context.done(null, event + 'Lambda'); // SUCCESS with message };
  23. 23. How to build an even better backend? Back-end logic DatabaseMobile
  24. 24. Microservices with API Gateway and Lambda Amazon Lambda Amazon API Gateway Amazon DynamoDB Microservice
  25. 25. 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
  26. 26. 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) • Provides a caching layer for your calls • Enables CORS for all AWS service for web apps
  27. 27. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  28. 28. Amazon S3 & Amazon CloudFront • Amazon S3 • Highly available object storage • Designed for 99.999999999% durability • Offers HTTP / HTTPS endpoint to objects • Amazon CloudFront • Content Delivery Network with 54 edge locations across the world • Caches content on edge locations for low latency Amazon S3 Amazon CloudFront
  29. 29. // Creating the transfer utility AmazonS3 s3 = new AmazonS3Client(cognitoProvider); TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext()); // Upload file TransferObserver observer = transferUtility.upload(bucket, filename, file); // Download image TransferObserver observer = transferUtility.download(bucket, filename, file); Use Transfer Utility for S3
  30. 30. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  31. 31. Amazon SNS Mobile Push Notifications • Amazon SNS is a fully managed, cross-platform mobile push intermediary service • Fully scalable to millions of devices • Allows 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
  32. 32. AmazonSNSClient snsClient = new AmazonSNSClient(); CreatePlatformEndpointRequest request = new CreatePlatformEndpointRequest() .withPlatformApplicationArn(platformApplicationArn) .withToken(deviceToken); //register device CreatePlatformEndpointResult result = snsClient.createPlatformEndpoint(request); Device Registration – Code example
  33. 33. var sns = new SNS({ region: ’ap-southeast-1’}); // send message to single device (could also be a topic) var endpointArn = 'arn:aws:sns:ap-southeast- 1:12345678:endpoint/5d3954e1-7d68-365a-80c2-95ae98ae4336'; // Message to send var message = ’New player just joined your game!'; sns.sendMessage(endpointArn, message, function(err, messageId) { if (err) console.log(’Error occured with device %s', endpointArn); }); Send Push Notifications via AWS Lambda
  34. 34. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  35. 35. Amazon DynamoDB • Schemaless Data Model • Seamless scalability • No storage or throughput limits • Consistent low latency performance • High durability and availability • Replicated across 3 facilities DynamoDB table items attributes Fully Managed NoSQL Database Service
  36. 36. @DynamoDBTable(tableName = ”User") public static class User { private String hash, nickname, avatar; private int score; @DynamoDBHashKey(attributeName = ”hash") public String getHash() { return hash; } public void setHash(String hash) { this.hash = hash; } @DynamoDBAttribute(attributeName=”nickname") public String getNickanme() { return nickname; } ... hash nickname avatar score abce6 Oli4 s3://bkt/av1.jpg 1500 feru64 LoLZ s3://bkt/lolz56.jpg 800 4568c L33t s3://bkt2/cat.png 750 Table: User Object Mapper Example - Class
  37. 37. // Create a user object User user = new User(); note.setHash(”abce64”); note.setNickname(”Oli4"); note.setAvatar(”s3://mybucket/av1.jpg"); note.setScore(0); // Save user object to DynamoDB mapper.save(user); // Update score and save user again user.setScore(user.getScore()+100); mapper.save(user); // Load another user User anotherUser = mapper.load(User.class,”asian_tiger_1234”); Object Mapper Example – Store and Update
  38. 38. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  39. 39. Stream in Real Time: Amazon Kinesis • Real-Time Data Processing over large distributed streams • Elastic capacity that scales to millions of events per second • React In real-time upon incoming stream events • Reliable stream storage replicated across 3 facilities Amazon Kinesis
  40. 40. KinesisRecorder String kinesisDirectory = "YOUR_UNIQUE_DIRECTORY"; KinesisRecorder recorder = new KinesisRecorder( cognitoProvider, Regions.AP_SOUTHEAST_1, getDir(kinesisDirectory, MODE_PRIVATE)); recorder.saveRecord(”Message1".getBytes(),"MyStreamName"); recorder.saveRecord(”Message2".getBytes(),"MyStreamName"); recorder.submitAllRecords();
  41. 41. Process and Notify in AWS Lambda exports.handler = function(event, context) { event.Records.forEach(function(record) { payload = new Buffer(record.kinesis.data, 'base64').toString('ascii'); UserEvent event = new UserEvent(payload); if (event.position == TREASURE_BONUS_COORD) { var message = ’You found the special treasure!'; sns.sendMessage(endpointArn, message); } }); context.succeed(); };
  42. 42. Amazon Mobile Analytics Amazon Device Farm AWS IAM Amazon Cognito Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Lambda Amazon SNS Mobile Push AWS Mobile SDK Amazon Kinesis Authenticate & Sync Authorize access Analyze User Behavior Store Content Test across Devices Deliver Content Store Data Record Real-Time EventsRun Business Logic Send Push Notifications
  43. 43. Great, AWS has all we need, but it’s a bit complex!
  44. 44. AWS Mobile Hub • Allows to build mobile apps within minutes • Single integrated console to use all AWS services for mobile • Automatically provisions all necessary AWS services based on selected features • Automatic code generation for iOS (Objective-C / Swift) and Android • Uses security best practices with AWS IAM
  45. 45. AWS Mobile Hub
  46. 46. Create a project and add features
  47. 47. Thank you! Olivier Klein 奧樂凱 Solutions Architect, Greater China

×