[Today’s random Sourcerer profile: https://sourcerer.io/banister]

Building REST services with Serverless framework, in Node.js, AWS Lambda and DynamoDB

David Herron
Sourcerer Blog
Published in
18 min readJun 8, 2018

--

Serverless computing is a very popular approach to building server-side applications, and the Serverless framework claims to be the most flexible way to build Serverless applications. Rather than stick with a given particular Serverless implementation from Amazon, Google, IBM, Microsoft or others, the Serverless framework abstracts away the particulars of each.

The Serverless framework lets you target any of the popular Serverless platforms. Well, you can target the platforms the Serverless framework supports. See the list on their website: https://serverless.com/framework/docs/providers/

With the Serverless framework, you create a service description using a serverless.yml file, create any code or other assets, and use the serverless command-line tool to upload your service, and to interact with facilities provided by your chosen platform. Behind the scenes it translates your service description file and other source files into the deployment files required by your chosen platform. For example, during deployment to Amazon Web Services, the serverless CLI tool creates an AWS CloudFormation description of your service, and uses the AWS API to create required services and configuration settings in the AWS services described in your serverless.yml file.

Earlier we used the Amazon AWS GUI user interface to configure a simple REST service using API Gateway and backed by a Node.js Lambda function. It took a lot of clicking around in the AWS GUI to get everything setup. While that’s useful for getting started with AWS, it’s not any kind of software development best practice. Instead it is best to have source code checked into source control system like Git. With the Serverless framework, you write source code on your laptop that is easy to commit to a source repository like Git.

In this article we’ll implement a simple REST API backed up by a DynamoDB table. To give a rationale, the table will store messages similar to a discussion board like Slack or Sourcerer Channels. The API will support querying for messages in a given “room”, or by the “user”, and will sort the messages in reverse chronological order so the latest shows at the top of the list. These queries will require a DynamoDB global secondary index.

--

--

Software Engineer and author (Node.js Web Development and more) passionate about Node.js, climate change, EV’s, and clean energy. https://davidherron.com