Engage Your Customers with Amazon SNS Mobile Push (MBL308) | AWS re:Invent 2013

Embed Size (px)

DESCRIPTION

Amazon SNS mobile push is a scalable, fully-managed, cross-platform mobile push notifications service. In this session, we show you how to implement a massively scalable notification system across multiple platforms (including Apple, Google, and Kindle Fire devices). We cover common design patterns including the code you need, and we demonstrate live on stage just how fast and scalable SNS can be. Also hear from customers who have combined Amazon SNS with Amazon Redshift and Amazon DynamoDB to engage their own customers with precisely targeted messages.

Citation preview

  • 1.Engage Your Customers with Amazon SNS Mobile Push Constantin Gonzalez, Solutions Architect, Amazon, Germany Pablo Varela, Software Engineer, Plumbee November 15th, 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. Friday, November 15, 13

2. 65% of mobile apps are abandoned within 90 days.http://blog.flurry.com/bid/90743/App-Engagement-The-Matrix-ReloadedFriday, November 15, 13 3. understanding and improving user engagement is the new currency of doing business in the new digital world. Peter Farago, Flurry.comhttp://blog.flurry.com/bid/90743/App-Engagement-The-Matrix-ReloadedFriday, November 15, 13 4. Mobile push notifications engage customers when your app is not currently active. Users opt-in to receive them Delivered to a specific app on a specific device Short messages: read, ignore, or acknowledge to launch the appFriday, November 15, 13 5. In this session, well cover: How push notifications work. A simple, scalable, robust & cross-platform way to deliver push notifications that you can start using now. A real-world example for sending massive amounts of targeted push notifications to mobile users.Friday, November 15, 13 6. Push Notifications Under the CoversFriday, November 15, 13 7. Your cloud application directs mobile push notifications to a specific app on a specific deviceCloud AppFriday, November 15, 13Mobile Apps 8. Notifications are delivered via platform-specific push services, which keep connections with their devices.Platform Service Cloud AppFriday, November 15, 13Mobile Apps 9. Developers manage tokens for each device, and must proactively swap or disable them based on feedback. Token FeedbackPlatform ServiceToken RegistrationFriday, November 15, 13 10. ChallengesFriday, November 15, 13 11. Each platform-specific push service works differently.Apple APNsGoogle GCMAmazon ADM Friday, November 15, 13 Different APIs Different Features Different Feedback 12. Token Housekeeping Can be Complex Token FeedbackPlatform ServiceToken RegistrationFriday, November 15, 13 Regularly connect to the platform service Handle feedback for failed/ stale notifications Blacklist tokens Establish good reputation with platform services etc. 13. Push notifications get even more complex as you scale to support millions of devices.Cloud AppPlatform Services Friday, November 15, 13Mobile Apps 14. Amazon SNS Mobile PushFriday, November 15, 13 15. Amazon SNS Mobile Push is a managed, scalable, cross-platform push intermediary service. Apple DevicesGoogle Devices Amazon SNS Mobile PushFriday, November 15, 13Kindle Devices 16. You can send a distinct payload for each platform, or publish one common message for all platforms. PublishAppleGoogle Kindle FireFriday, November 15, 13PublishKindle FireAppleGoogle Kindle FireKindle Fire 17. You can publish unique messages to individual devices, or broadcast identical messages to many devices at once. Direct PublishingBroadcast with SNS TopicsPublish Publish PublishFriday, November 15, 13Publish 18. Amazon SNS consumes feedback from each platform and manages swapping and disabling tokens on your behalf.Token FeedbackCloud AppFriday, November 15, 13Amazon SNS Mobile PushToken Registration Write to one stable endpoint per device You can access the feedback, but you dont have to do so in order to use Amazon SNS 19. Getting StartedFriday, November 15, 13 20. Step 1: Write your mobile app Use the mobile app platforms push notification libraries as you normally would.Friday, November 15, 13 21. Step 2: Obtain Application Prerequisites APNs: Apple Push Notification service SSL certificate Application Private Key GCM: API Key (Sender Auth Token) ADM: Client ID Client secretFriday, November 15, 13 22. Step 3: Register Your Mobile App with AWSAmazon SNS Mobile PushFriday, November 15, 13 23. Step 4: Obtain a Token/Registration ID from the device APNs: Device Token GCM: Registration ID ADM: Cloud App Registration IDFriday, November 15, 13 24. For existing devices Use the console for .csv import arn:aws:sns:eu-west-1:121fStep 5: Add Token/Registration ID to Amazon SNSCloud AppAmazon SNS Mobile Push Or use CreatePlatformEndpoint API For future devices Use a proxy server and the CreatePlatformEndpoint API Or use the AWS token vending service and let devices register themselves Receive an ARN back Friday, November 15, 13 25. Step 6a: Send Push Notifications via the ConsoleHello world!Friday, November 15, 13 26. Step 6b: Send Push Notifications via the API MyMac:~ glez$ python Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import boto >>> import boto.sns >>> boto.sns.connect_to_region("eu-west-1").publish( ... message="Hello world!", ... target_arn="arn:aws:sns:eu-west-1:979463966312:endpoint/APNS_SANDBOX/ Push2reInvent/fc1234a1-67ef-4f62-b31a-ac320bf7631f") {u'PublishResponse': {u'PublishResult': {u'MessageId': u'1893fa9d-7478-5137be1d-b06928d999d0'}, u'ResponseMetadata': {u'RequestId': u'c3c26267-92af-50b3-b529-2893ce0e4854'}}} >>>Friday, November 15, 13 27. Step 7: ReceiveFriday, November 15, 13 28. User/Device management Use CreatePlatformEndpoint to register new tokens/IDs along with user data Use ListEndpointByPlatformApplication to discover registered endpoints Manage ARNs and associated data in Amazon DynamoDB Publish to individual ARNs, or Use Amazon SNS topics for 1:many messaging Coordinate publishing with Amazon SQS or Amazon SWFFriday, November 15, 13 29. DemoFriday, November 15, 13 30. Quick ReviewAmazon SNS Mobile PushFriday, November 15, 13 Cross-platform push to Apple, Google and Amazon Seamless scalability with durable, reliable deliveries Easy token management 1m free per month, and $1.00 per million thereafter 31. Pablo Varela, Software Engineer, PlumbeeFriday, November 15, 13 32. Mirrorball Slots - MobileFriday, November 15, 13 33. Mirrorball Slots - MobileFriday, November 15, 13 34. Mirrorball Slots - ChallengesFriday, November 15, 13 35. Our customers ask for notifications! Some of us have very busy lives and cant be checking the game 24/7. It would be great to get a notification when a challenge starts. Thanks!Friday, November 15, 13 36. Use cases Retention / reactivation Day 2, day 7 retention active players (active in 7 days) D7,D10,D14,D21,D28 reactivation Challenge start/ends/redemption New features/gamesFriday, November 15, 13Targeted promotions Spenders categorisation Last spent New user promos Time-limited promo start/end 37. Design Goals Easy to add new campaigns Fine grained targeting Scales linearlyFriday, November 15, 13 38. Building blocksData CollectionFriday, November 15, 13TargetingMobile Push 39. Data CollectionFriday, November 15, 13 40. Data Collection Collect everything There is not such a thing as too much data! Targeting as effective as your data Fine granularity depends on data analysisFriday, November 15, 13 41. Data Collection log actionslog logApplication ServersFriday, November 15, 13Analytics Amazon SQS 42. Device Registration Code example private String getArnForDeviceEndpoint( String platformApplicationArn, String deviceToken) { CreatePlatformEndpointRequest request = new CreatePlatformEndpointRequest() .withPlatformApplicationArn(platformApplicationArn) .withToken(deviceToken); CreatePlatformEndpointResult result = snsClient.createPlatformEndpoint(request); }return result.getEndpointArn();Friday, November 15, 13 43. Device Registration Logging private String registerEndpointForApplicationAndPlatform( final long plumbeeUid, String platformARN, String platformToken) { final String deviceEndpointARN = getArnForDeviceEndpoint(platformARN, platformToken); sqsLogger.queueMessage(new HashMap() {{ put("notification", "register"); put("plumbeeUid", plumbeeUid); put("provider", platformName); put("endpoint", deviceEndpointARN); }}, null); }return deviceEndpointARN;Friday, November 15, 13 44. Device Registration Event example {"sId": "2fa5e687-c692-4c60-8bf9-19d3b3bef30f", "rId": "40f3aa74-1653-422f-a484-b98dbb32bda2", "timeStamp": 1381853084268, "testVariant": "", "m-mbs-app-service-version": "m-mbs-app-1381818956", "metadata": { "plumbeeUid": XXXXXXX, "notification": "register", "provider": "apns", "endpoint": "arn:aws:sns:us-east-1:300361537691:endpoint/APNS/ MIRRORBALL_SLOTS_CI/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" } }Friday, November 15, 13 45. Data Collection (II) consumeAnalytics Amazon SQSFriday, November 15, 13archiveApache FlumeAmazon S3 Event Logs 46. Data Collection (III)ClusterconsumeKPIs updateAmazon SNSAmazon Redshift Event Logs Friday, November 15, 13Amazon EMRAmazon S3 47. User TargetingFriday, November 15, 13 48. User targeting SQL queries against Amazon Redshift Thats it!Friday, November 15, 13 49. User targeting Query example -- Target all mobile users SELECT plumbee_uid, arn FROM mobile_userFriday, November 15, 13 50. User targeting Query example (II) -- Target lapsed users (1 week lapse) SELECT plumbee_uid, arn FROM mobile_user WHERE last_play_time < (now - 7 days)Friday, November 15, 13 51. User targeting Query example (III) -- All the users that spend between 6h and 9h UTC on -- Mondays and didn't spend in the last 7 days SELECT plumbee_uid, arn FROM user_spending_activity WHERE time_slice = 3 AND plumbee_uid IN ( SELECT plumbee_uid FROM user_metrics WHERE last_purchase_time < (now - 7d)Friday, November 15, 13 52. Mobile PushFriday, November 15, 13 53. Mobile Push Code example SNS publish private void publishMessage(UserData userData, String jsonPayload) { amazonSNS.publish(new PublishRequest() .withTargetArn(userData.getEndpoint()) .withMessageStructure("json") .withMessage(jsonPayload)); }JSON payload { "default": "The 5 day Halloween Challenge has started today! Touch to play now!", "APNS": "{"aps" : {"alert":"Halloween Challenged has started!"","sound":"default" },"id":"XXXX ","tag":"challenge-start" }" } Friday, November 15, 13 54. Mobile Push Amazon SWF for orchestration Amazon Redshift for targeting Amazon SNS for the actual pushFriday, November 15, 13 55. Mobile Push - Scheduling querySchedulingFriday, November 15, 13queryPublish ServiceAmazon SWF 56. Mobile Push - Targeting queryqueryAmazon EC2 Worker Amazon SWF (Segmentation) Friday, November 15, 13target usersAmazon RedshiftAmazon S3 57. Mobile Push - Processing batch 1 - Nbatch N - Mpartition publish partitionpushpushpublishAmazon EC2 Amazon SWF Children workflows Read data + push Decider (Batch Processing)Friday, November 15, 13End User 58. Mobile Push - Reporting example The following message has been sent to NNNNNN devices in m min, ss sec: The 5 day Halloween Challenge has started today! Touch to play now! Targeting query: SELECT m_arn.plumbeeui, DISTINCT(m_arn.endpoint) FROM mobile.lu_user m_user, mobile.lu_notifications_arn m_arn WHERE m_user.plumbeeuid = m_arn.plumbeeuid AND country_code IN (:america) GROUP BY m_arn.endpoint Workflow Execution Stats * * * *number number number numberof of of ofdevices targeted: NNNNNN notifications sent: NNNNNN notifications that failed (excluding disabled devices): 0 disabled devices: NNNNClick here for workflow execution details.Friday, November 15, 13 59. Day 2 retention - No Push vs Push Without Push40With Push30 20 10 0 Day 1Friday, November 15, 13Final DayRedemption Day 60. Summary Collect and analyze data: Amazon SQS, Amazon S3, Amazon EMR, Apache Flume, Amazon Redshift Targeting: SQL queries Mobile Push with Amazon SNS Orchestration with Amazon SWFFriday, November 15, 13 61. More Information Open Source projects https://github.com/plumbee Plumbee Engineering Blog http://bit.ly/1hqWBD4 Email [email protected], November 15, 13 62. Extensive SDK and IDE support enables you to build applications tailored to your language or platform. SDKs for your preferred platform and languageAndroidiOSJavanodeJS.NETintegrated into your preferred IDEEclipseFriday, November 15, 13Visual StudioCLIPowershellPHPPythonRuby 63. More Information Amazon SNS Detail Page and Docs http://amzn.to/179ee7rAmazon SNS Mobile Push Getting Started + Sample Apps http://amzn.to/15rs1DV Email [email protected], November 15, 13 64. We hope your mobile app never gets abandoned!Friday, November 15, 13 65. Please give us your feedback on this presentationMBL308 As a thank you, we will select prize winners daily for completed surveys!Friday, November 15, 13Thank You 66. Developers use intermediaries to abstract platform-specific APIs and manage tokens for millions of apps.Push Intermediary Friday, November 15, 13 67. Developers use intermediaries to abstract platform-specific APIs and manage tokens for millions of apps.Abstraction so your app can engage users on any platform Manage tokens to ensure messages are delivered reliablyFriday, November 15, 13Operational complexity Scalability takes work Cost even though the platform services themselves are free 68. SNS offers easy scalability, so you can just start sending more messages as your app achieves scale. Go from a few messages to hundreds of millions Go from a few devices to hundreds of millions ...without provisioning, configuring or managing ...without sacrificing reliable, durable deliveryFriday, November 15, 13 69. You can get started for free. 1 Million Free per Month 1 million publishes + 1 million mobile push notifications $1.00 per Million Thereafter $0.50 per million publishes + $0.50 per million mobile push deliveries When you broadcast with SNS Topics, your effective price can be lowerFriday, November 15, 13