AWS Lambda is an AWS service that runs your code in response to events or HTTP requests. Here's how to easily build and deploy a Node.js Lambda microservice.

Introduction

AWS Lambda is a service from the Amazon Web Services family which runs your code based on various events. When you create a Lambda function and deploy your code to it, AWS Lambda takes care of provisioning and managing servers that run your code.

This tutorial will show you how to develop a Node.js Lambda function from scratch and deploy it to AWS Lambda. To achieve a continuous delivery workflow for our function, we will automate the deployment process through Semaphore's integration with Lambda.

Once the function is complete, it will text message anyone who breaks the build on your project on Semaphore.

The function we are developing will use:

Grunt (a task runner for Javascript, which we will use to invoke our function locally)

NPM (the primary package manager for Node.js),

Twilio API (we will use Twilio's API to send text messages)

AWS SDK for Node.js (a simple and easy-to-use API for AWS services)

Prerequisites

To develop this function, you will need:

An AWS account

A GitHub repository to which we will push our code

A Semaphore project where we will build and deploy the code,

A Twillio account for texting users who break the build (we'll use the free account).

Initializing a Lambda Function

A Lambda function is basically the code that is run when a function is invoked. Typically, it is invoked by the events that you define.

Let's create a new Lambda function. To do so, we need to go to the Lambda console and click on Get Started Now.