Using a REST API with Amazon Web Services, Part 1

by 

| January 9, 2019 | in

Amazon Web Services (AWS) has a lot of services that make it quick and easy to build software solutions. They provide a lot of services that don’t require a lot of effort to set up.

In this post, we are going to set up an AWS backend that can return some contacts that we store on the server. This blog post is part of a larger series where we are going to build an AWS backend to manage a contact list stored in DynamoDB.

During this series, we are going to use many technologies including API Gateway, Lambda Functions, and DynamoDB, and we will be creating an API in the cloud that can CRUD (Create, Read, Update, and Delete) contacts. However, the focus of this blog post will be the R of CRUD. We are going to read some contacts from a DynamoDB table.

First, we need to create an AWS account. This is pretty basic, you just have to sign up and provide credit card information. Luckily, what we are building should be pretty cheap; it shouldn’t cost much (if anything).

Second, we need to create a DynamoDB table. Let’s be really creative with the name and call it “Contacts”.

We can manually write a few contacts to the database.

Now we must create a Lambda function to query the data by groupid. This is pretty easy to write, but we have to use the online editor within AWS. We will write this using JavaScript created in a text editor running on a web page. Now if that doesn’t sound like a situation just looking for problems. But for the purpose of this quick prototype it is okay. I wouldn’t recommend writing a lot of production code this way.

Why not write your production code this way? Because we are just dropping text into an AWS editor and are missing out on a lot of good development practices. First, we don’t have any layers in our software, just a function. This is going to make getting any reuse between our functions pretty difficult. But even more important than the reuse / architecture issues, we have no source control and continuous integration. This way of programming isn’t scalable to many developers and large systems.

To create this function, we must do it from within the AWS console. We will click the “Create Function” button, which can be found on the Lambda home screen.

Then we will write some JavaScript code in our web browser.

Click “Test” to run the code. The Lambda function will query the contacts table and return the record I created earlier.

In the next blog post in this series, we will dive a little deeper into these Lambda functions and write a method that finds a single contact. We will also write Lambda functions to create and update our contacts.

If you have any questions or comments, hit me up on Twitter.

author avatar
Chad Michel Senior Software Architect
Chad is a lifelong Nebraskan. He grew up in rural Nebraska and now lives in Lincoln. Chad and his wife have a son and daughter.

Related posts