You are here

How to Launch an API With Amazon’s Lambda and API Gateway

AWS Lambda is the service that automates the running of code using the AWS infrastructure, creating a highly available and reliable Web service that is secure and scales as needed, removing the need for a full-stack solution to run just a few lines of code. Its event-driven design allows each AWS service to log an event, such as an API call, and trigger an action, such as run a predefined script.

As an example, if you wanted to upload multiple images from a Web app to your S3 bucket, and then run a conversion once uploaded to turn them into thumbnails, the problem sounds simple but the solution is fairly complex. It involves provisioning machines to handle the requests,
implementing a queuing system to store the jobs, provisioning more machines to perform the conversions, and deploying code to each machine multiple times.

AWS Lambda streamlines the entire process by tying the code to the data as it uploads to the cloud. Each event triggers the subsequent action with resources automatically handled in the background, so there is no need manage each individual process. In this tutorial on ReadWrite, Pete Gamache guides followers through building a simple request handler that leverages Lambda and AWS API Gateway to make development quick and easy.

The first step is to write the request handler in JavaScript, which relies on a working Node.js installation, before zipping the code for importing to Lambda. Followers are then guided through setting up and testing the Lambda, before creating the API and its method in API Gateway.

The author also provides several tips and tricks to ease development, but all of the code is provided and simply copy/pasting all of it should have your API up and running in around 10 minutes.

Be sure to read the next Application Development article: How to Build Microservices with Docker and the Rails API Gem

Original Article

How To Build An API In 10 Minutes