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.

(WRK302) Event-Driven Programming


Published on

Interested in learning about event-driven programming? In this session we will introduce you to some of the basics of using Amazon DynamoDB, its newly launched Streams feature and AWS Lambda. We will provide an overview of both AWS products and walk you through the process of building a real-world application using AWS Triggers, which combines DynamoDB Streams and AWS Lambda.

Published in: Technology

(WRK302) Event-Driven Programming

  1. 1. © 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Daniela Miao, Software Engineer, AWS, DynamoDB October 2015 WRK302 Event-Driven Programming With Amazon DynamoDB Streams and AWS Lambda
  2. 2. What to Expect from the Session Why Amazon DynamoDB? Amazon DynamoDB Basics Amazon DynamoDB Streams AWS Lambda Building an event-driven application Summary
  3. 3. Why Amazon DynamoDB?
  4. 4. Customers wanted a database with… Reliably low latency at any scale Elastic throughput and storage Flexible queries and data models Strong consistency Availability and fault-tolerance
  5. 5. What Amazon DynamoDB Provides… Fully-managed NoSQL database service Consistent, single-digit millisecond latency Independent throughput and storage scaling Supports both document and key-value data models Automatic data replication across three facilities
  6. 6. Amazon DynamoDB Basics
  7. 7. Data model Tables: collection of items Items: collection of attributes Attributes: name-value pairs • Scalar: number, string, binary, boolean, null • Multi-valued: string set, number set, binary set • Document: list, map
  8. 8. Data model RecordID PlayerName Score NickName 1 Alice 999 AliceTheMalice 2 Bob 888 Sample table: GameRecords • Note attributes can be optional
  9. 9. Primary key – hash RecordID PlayerName Score NickName 1 Alice 999 AliceTheMalice 2 Bob 888 Hash type primary key: primary key is made of one attribute, required for all items
  10. 10. 55 A9 54 Distributing hash keys Hash key uniquely identifies an item Hash key is used for building an unordered hash index 00 FF RecordId = 1 Name = Alice Hash (1) = 7B RecordId = 2 Name = Bob Hash (2) = 48 RecordId = 3 Name = John Hash (3) = CD Key Space
  11. 11. 55 A954 AA FF Distributing hash keys Table can be partitioned for scale 00 FF RecordId = 1 Name = Alice Hash (1) = 7B RecordId = 2 Name = Bob Hash (2) = 48 RecordId = 3 Name = John Hash (3) = CD Key Space
  12. 12. Primary key – hash and range Customer# Order# Item 1 10 Shoes 1 11 Toys 2 11 Pen Hash and range type primary key: the primary key is made of two attributes, required for all items
  13. 13. Hash range table Within an unordered hash index, data is sorted by the range key 00 FF Hash (2) = 48 Customer# = 2 Order# = 10 Item = Pen Customer# = 2 Order# = 11 Item = Shoes Customer# = 1 Order# = 10 Item = Toy Customer# = 1 Order# = 11 Item = Boots Hash (1) = 7B Customer# = 3 Order# = 10 Item = Book Customer# = 3 Order# = 11 Item = Paper Hash (3) = CD 55 A954 AA Partition 1 Partition 2 Partition 3
  14. 14. Query and scan A query operation finds items in a table using only primary key attribute values. • Hash key attribute-value pair is required • Range key attribute-value pair is optional • In the previous example, query for all orders of a specific customer by setting “customer# = 1". A scan operation examines every item in the table. • Returns all of the data attributes for every item
  15. 15. Amazon DynamoDB Streams
  16. 16. Amazon DynamoDB StreamsAmazon DynamoDB Streams Stream of updates to a table in a continous pipeline Records all modifications made to items of the table Scales with table size and throughput StreamsTable DynamoDB Client Application Updates
  17. 17. Customer application Amazon DynamoDB replicator using DynamoDB Streams Copies incoming data to a different table in real-time Blog post published describing the application “DynamoDB delivers even more stability, redundancy, and speed for our document-based data and requires less hands-on administration, so we can focus on building the software that powers Mapbox.”
  18. 18. View Type Record Content Old image—before update RecordID = 1, Name = Alice New image—after update RecordID = 1, Name = Alison Old and new images RecordID = 1, Name = Alice RecordID = 1, Name = Alison Keys only RecordID = 1 View types UpdateItem: (RecordID = 1, Name = Alice)  (RecordID = 1, Name = Alison) Entire image of the item is returned, not just the changes
  19. 19. Stream Table Partition 1 Partition 2 Partition 3 Partition 4 Partition 5 Table Shard 1 Shard 2 Shard 3 Shard 4 KCL Worker KCL Worker KCL Worker KCL Worker Amazon Kinesis Client Library Application DynamoDB Client Application Updates Amazon DynamoDB Streams and Amazon Kinesis Client Library
  20. 20. Analytics with Amazon DynamoDB Streams Collect and de-dupe data in DynamoDB Aggregate data in-memory and flush periodically Performing real-time aggregation and analytics
  21. 21. DynamoDB Streams Open source cross-region replication library Asia Pacific (Sydney) EU (Ireland) Replica US East (N. Virginia) Cross-region replication
  22. 22. Cross-region replication library Horizontal scaling Bootstrapping existing items Fault tolerance Optimized for cost and performance
  23. 23. AWS Lambda
  24. 24. AWS Lambda Event-driven compute in the cloud Lambda functions: stateless, request-driven code execution • Triggered by events in other services: e.g., write to an Amazon DynamoDB table Ability to transform data as it reaches the cloud
  25. 25. AWS Lambda Customers can focus on business logic, no need to manage infrastructure Lambda scales to match the event rate Pay for only what you use • Fine-grained pricing: purchase compute time in 100ms increments • No hourly, daily, or monthly minimums
  26. 26. Popular usage scenarios Data triggers with Amazon S3 or Amazon DynamoDB Audit and notify • Monitor AWS CloudTrail logs and use Lambda functions to send Amazon SNS notifications Custom deployment rules using AWS CloudFormation Validate cross-device sync data with Amazon Cognito Custom events by publishing to Amazon Kinesis
  27. 27. Amazon DynamoDB Streams and Lambda
  28. 28. Sample Scenario Amazon DynamoDB table and Streams AWS Lambda Send notification via Amazon SNS Update another table
  29. 29. Building an event-driven application
  30. 30. Popular usage scenarios Mobile gaming application GameScoreRecords table • Records of game scores • Want to implement a list of aggregate scores for each user GameScoresByUser table updated by AWS Lambda
  31. 31. Self-paced Hands-on Lab Zip file included with the workshop package Use lab guide to complete each exercise in your group Solutions provided in a separate directory – do NOT use unless truly stuck
  32. 32. Remember to complete your evaluations!
  33. 33. Use QR code or link above to download the group activity package and follow the lab guide.
  34. 34. Thank you! After the break, there will be a group-based activity to build an event-driven application