Skip to main content

Learning AWS Lambda, API Gateway, and DynamoDB

The first step I'm taking in my IoT journey is to learn about Amazon Web Services (AWS). Many IoT products utilize (or can utilize) this service, which is why it seems like a good starting place. Cloud computing is essential to IoT, since very little processing is done at the local level (hence: "internet").

If you aren't aware, AWS is a serverless platform that allows developers to run code, build databases, and much more all in the cloud. There are several advantages to using AWS:


  • frees developers and businesses up from having to administer to their own servers, since Amazon takes care of all server maintenance
  • virtually unlimited scaling, since AWS will dedicate more or fewer servers as needed for your data
  • only pay for the time when your code is called (in the case of AWS Lambda) -- not idle time

To get started, I followed these tutorials. They walk you through how to set up an AWS account and the AWS CLI (Command Line Interface), as well as how to use the Lambda, API Gateway, and DynamoDB services. All of these are basic services that will be essential in many IoT projects

After completing the first step in the tutorial (I already had an AWS account), I have the AWS CLI installed, which means I can use the Windows Command Prompt to efficiently perform AWS-related tasks. So far I've used it to configure an IAM (Identity and Access Management) role, configure my root account, and list all of the Lambda functions in my account.

After completing the second step in the tutorial, creating a hello-world style Lambda function, I now understand the basics of working in the Lambda console. I can save and test function code, and modify and utilize key-value pairs as function input. I can also analyze the output of running a function.

While completing the third step in the tutorial, creating a microservice using Lambda and API Gateway, I came across a couple of issues. First of all, I was confused about the part that says "create a DynamoDB table with streams enabled". While setting up the DynamoDB table, there didn't seem to be an option to enable streams. I simply saw this screen:
There's nothing about "streams" on there. Wanting to get my table set up correctly, I scoured the internet for a solution, to no avail. I finally decided to go ahead and click "Create", although I had no idea if my database would be set up properly. It was then that I realized that streams can only be enabled after creating the database. In the screen below, you have to click "Manage Streams"...


And then choose an option. Any option will enable streams, but beyond that more research may be required to determine which option will be best for your purposes. I left it at the default option.







Other than that, I didn't have any trouble following AWS's tutorial. However, the end was quite anti-climactic. It shows you how to send an HTTP GET request to your function by pasting the request in the test event configuration. The result was basically nothing, since I didn't have anything in my DynamoDB Table.




So, I decided to do some research to see how to insert new rows via HTTP requests. (You can also insert new rows through the user interface, but I thought doing so programatically may be more useful for IoT projects.) It appears this is the request syntax for updating a DynamoDB table. After attempting to use it, I've decided to make a subsequent post dedicated to that topic solely. 


Another thing that didn't click for me at first was the role API Gateway played in the architecture. You can see the connection by going to the API Gatway console, selecting the ANY function, and clicking Test. 

Then, choose the GET method (or whichever method you prefer; results may vary). In Query Strings, you can set any key-value pairs that your function uses. For example, I typed TableName = MyTable. Select "Test", and your API will call your Lambda function and show you the same output you would see testing it in the Lambda console. 









Here is a video demonstrating my results: 


Overall, I think this was a very successful first step for me into the world of IoT. I'll be able to use these basic AWS technologies in countless projects as I learn about the new tools we developers have at our disposal today. 

Comments

Popular posts from this blog

Reading from and Modifying a DynamoDB Table using API Gateway

In many IoT (Internet of Things) projects, it is necessary to read from and write to a database. AWS has an application called DynamoDB that is a NoSQL database, exactly what we need. While it is very simple to add/modify/delete entries in this database via the user interface, it's not so obvious how to do so via HTTP API calls. So, in this post I'll continue the AWS portion of my journey into IoT to learn how to do just that. I'll be following  this  tutorial. The first thing I encountered is I wasn't sure if I was supposed to follow the steps under "Defining APIs", or if that was just knowledge for later. Turns out, that was knowledge for later. If I had any prior experience with APIs I probably would have realized this. Basically, the "API definition"s are just a high-level plan for what you want your API requests to look like in the end. In my opinion this information should go in the "Creating the APIs" section. Moving through "Cr...

Arduino Project: Sound Alert via Twitter

For my second IoT project using Arduino MKR1000, I'll employ a sound sensor to send out alerts via Twitter when a loud sound is detected. This could have many uses, ranging from informing the inhabitants of a house that there is someone at the door, informing a car owner that their alarm is going off, or residents that a gunshot has gone off in their neighborhood. See my previous posts to learn about the setup process for the Arduino MKR1000, which is wifi-enabled without any additional extensions. I will be using the Arduino IDE to compile the code. For hardware, I'll be using the sound sensor I purchased here , as well as my Arduino, three solder-free wires, a generic breadboard, and a Kindle power cable (this probably isn't the safest way to power Arduino, but it's what I had). I'll be following this  tutorial to set up the sound detector, as well as some code from here  to utilize Twitter. The sound setup tutorial was very simple and one of the clearest wiring g...

Deep Learning - Recurrent Neural Networks (RNNs)

The latest Deep Learning topic I've been exploring is the Recurrent Neural Network (RNN). It has many use cases, including: time series extrapolation (i.e. given historical data, predict future output); object trajectory; and natural language processing (NLP). The code I wrote during this section of the course I'm taking can be found here . For my summary of RNNs, click here . Here are the notes I took while watching the lectures: RNN Theory Examples of Sequences Time Series Data (e.g. stock prices, sales rates) Sentences (i.e. natural language) Audio/Music Car Trajectories (where a car will go in a situation) [1,2,3] shifted one time step into the future would be [2,3,4] will train a network to predict y-values for this A normal neuron has input, activation function, then output A Recurrent Neuron sends output back to itself this process is called “unrolling” the neuron note that the input of each neuron is a summation from both ...