You are here

How to Create a Simple REST Service Using AWS Lambda

REST (REpresentational State Transfer) has become one of the most important technologies for Web applications since its introduction over 15 years ago. The architectural style allows the creation of Web services that are lightweight, scalable, and maintainable, and they are driving business growth in a huge range of industries today.

A RESTful service provides a window for clients to access resources (such as images, videos, Web pages, data, and more) typically over HTTP. When combined with Amazon Web Services' automated compute service Lambda, a REST service can implement a predefined function, such as running a piece of code when triggered by an event. In this tutorial on the FINRA Technology site, authors Nil Weerasinghe and Brijesh Patel explain how to build a simple REST service with authentication using Lambda, IAM (Identity and Access Management), and API Gateway.

This basic service will evaluate a number to determine whether or not it is a prime. The tutorial starts in Lambda with creating a function with a specified handler that will be invoked when the function is triggered. Then create a deployment package as a .zip file or standalone .jar before creating the function in the AWS console.

They then build a REST service to invoke the Lambda function using API Gateway, which requires access permission to the IAM user. The authors provide detailed instructions for each step, covering creating an API and a resource, creating and testing the POST method, and deploying and testing the API.

They then enable authentication using IAM that requires passing your AWS access key and secret key. Enable CORS (Cross-Origin Resource Sharing) for the new service, then you can begin calling the service using JavaScript. All code is supplied, and your simple REST service should be up and running in no time at all.

Be sure to read the next REST article: How to Create a Restful API Using Node.js and MongoDB

Original Article

Creating A Simple REST Service Using AWS Lambda, API Gateway, And IAM