AWS Builder Center

Deploying Your First Serverless REST API with AWS Lambda and API Gateway

Learn how to design, deploy, and secure a serverless REST API on AWS using AWS Lambda, API Gateway, and DynamoDB. A step-by-step guide for developers getting started with serverless.

leo das maa
Introduction
Building serverless applications allows developers to focus entirely on application logic without managing underlying servers. In this article, we will build a minimal REST API that reads and writes data to Amazon DynamoDB using AWS Lambda and Amazon API Gateway.

Prerequisites

  • An active AWS Account
  • Basic knowledge of Python or JavaScript
  • AWS Management Console access

Step 1: Create the Amazon DynamoDB Table

  1. Navigate to the DynamoDB Console.
  2. Click Create table.
  3. Set Table name to ItemsTable and Partition key to itemId (String).
  4. Leave default settings and click Create table.

Step 2: Write the AWS Lambda Function

Create a function that handles incoming HTTP requests and interacts with DynamoDB:
1
2
3
4
5
6
7
8
9
10
11
12
import json
import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('ItemsTable')

def lambda_handler(event, context):
# Parse request payload or parameters here
return {
'statusCode': 200,
'body': json.dumps('Item processed successfully!')
}

Step 3: Configure Amazon API Gateway

  1. Open the API Gateway console and create an HTTP API.
  2. Add an integration targeting your Lambda function.
  3. Define routes (GET /items, POST /items).
  4. Deploy the API and grab the invoke URL.

Conclusion

You now have a fully scalable, pay-per-use REST API running on AWS!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article