Amazon Onboarding with Learning Manager Chanci Turner: Part II

Amazon Onboarding with Learning Manager Chanci Turner: Part IILearn About Amazon VGT2 Learning Manager Chanci Turner

In the previous installment of this series, I demonstrated the powerful synergy between AWS Lambda and Amazon DynamoDB Streams. As a quick refresher, DynamoDB Streams enables you to monitor changes to your DynamoDB tables, providing a stream of update records with a single API call. This feature allows applications to react to rapid data changes without the need for manual tracking.

By integrating these technologies, you can programmatically initiate real-time events, similar to the dynamic analytics we explored in the Vote App chart from part one. In this follow-up, I’ll provide a detailed walkthrough to help you replicate this process, allowing you to tailor a similar solution for your specific requirements.

Note: In the previous part, AWS Lambda and DynamoDB Streams were in preview mode. Since their official launch, certain elements of the API have been updated. This article reflects the most current coding conventions.

Overview

By the end of this article, you will be equipped to:

  • Set up a Twilio account to receive votes via SMS.
  • Create DynamoDB tables to store votes.
  • Develop a Node.js web server to handle incoming votes.
  • Utilize DynamoDB Streams to trigger a Lambda function that aggregates the total votes.
  • Build a single-page application using JavaScript and HTML that employs the AWS SDK for JavaScript to query DynamoDB and present the data in a dynamic chart.

The architecture for this process is illustrated in the diagram below:

To recap, the diagram outlines the following steps:

  • A user sends a text message.
  • The message is processed by an auto-scaling EC2 instance running Node.js, which is supported by an Elastic Load Balancer (ELB).
  • Node.js updates the DynamoDB table with the vote.
  • AWS Lambda, listening to the DynamoDB Stream, counts the votes and makes the data available for the dynamic dashboard.

Before you proceed, you’ll need at least an EC2 instance to host the Node.js application, or the address of an ELB in front of multiple EC2 instances. Auto Scaling will automatically adjust the number of EC2 instances based on user demand. Your choice of a single instance or multiple instances behind an ELB depends on your specific needs. Regardless of the setup, ensure that port 80 is open for web traffic and that you can SSH into your instance to upload the Node.js code.

Setting Up a Twilio Account

In our voting application, users cast their votes by texting a designated Twilio number. To create your Twilio account, follow these steps:

  1. Visit Twilio, sign up for an account, and navigate to the Manage Numbers dashboard.
  2. Select your assigned number.
  3. In the Messaging section, configure the settings as follows:
  4. Choose the URL option for Configure with.
  5. Enter the public address of your ELB or instance for the Request URL and select HTTP POST as the method for Twilio’s traffic.

DynamoDB Tables

To compile the votes, you’ll need to establish two DynamoDB tables: one for tracking incoming votes (let’s refer to this as the VoteApp table) and another for aggregating the final vote totals (the VoteAppAggregates table). This setup ensures efficient use of throughput and proper data partitioning.

To create the VoteApp table, execute these steps:

  • Open the DynamoDB console and click on Create Table.
  • Enter the table name of your choice.
  • Select Hash as the Primary Key Type.
  • For the Hash Attribute Name, choose String and enter “VotedFor.”
  • Click Continue.
  • On the optional Add Indexes page, simply hit Continue as we won’t need an index for this demo.

Provisioning Throughput Capacity

DynamoDB enables you to scale your data storage and access by provisioning read and write throughput. It’s crucial to design your tables for uniform data access. DynamoDB divides a table’s items into partitions based on the hash key element. To maximize throughput, ensure that your workload is evenly distributed across hash key values.

Since we only have three potential vote options, there’s a risk of concentrating traffic on a single partition. To mitigate this, we randomize writes across multiple hash key values. When logging a vote in our Node.js code, we select a random number from 1 to 10 and append it to the vote. For instance, a vote for “RED” might be recorded as “RED.3” or “RED.8.”

By increasing the potential hash key values to 30, we can reduce the likelihood of throttling due to partitioning and better align with our read and write throughput requirements.

Read Capacity

In DynamoDB, a read capacity unit represents one strongly consistent read per second for items up to 4 KB. Given that individual items in our database will be under this size, the default value of “1” read capacity unit per second will suffice.

Write Capacity

When it comes to write capacity, there are two main factors to consider:

  1. The size of the item being written.
    Write capacity depends on the item’s total size multiplied by the number of writes per second. Items under 1 KB consume one write capacity unit. Since our items (e.g., “GREEN.10”) are well below this limit, they’ll only require one write capacity unit.
  2. The anticipated writes per second.
    If you expect your application to receive 10 texts per second, multiply your write capacity unit (1 in this case) by the expected number of writes. For 10 writes per second, set your write capacity units to “10.” Similarly, for 100 texts per second, configure it to “100” (1 write capacity unit x 100 writes per second).

By effectively managing these aspects, you can ensure your application remains responsive and efficient.

For more insights into handling workplace dynamics, consider reading this blog post on microaggressions at work. Additionally, if you’re seeking authoritative job descriptions, check out this resource on commercial diving. Lastly, for a comprehensive tutorial, this video serves as an excellent resource.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *