API Gateway with DynamoDB Integration

23rd August 2024

Overview

This documentation outlines the steps to create an API Gateway with GET and POST methods to interact with DynamoDB, serving as the database for movie details. It provides a seamless way to push and fetch movie data using API Gateway and DynamoDB integration.

Prerequisites

Steps

1. Create DynamoDB Table

Log in to your AWS Management Console and navigate to the DynamoDB service. Click on "Create table" and provide necessary details such as table name and primary key. For example, you can use "Movies" as the table name with "movie_id" as the primary key. Configure additional settings as per your requirements and click on "Create table".

DynamoDB Table Creation

2. Set Up IAM Roles and Policies

Navigate to the IAM service in the AWS Management Console. Click on "Roles" and then "Create role". Select "AWS service" and choose "Lambda" or "API Gateway" depending on your integration method.

IAM Role Creation

3. Set Up API Gateway

Navigate to the API Gateway service in the AWS Management Console. Click on "Create API" and choose "REST API". Select "New API" and give your API a name. Click on "Create API".

API Gateway Creation

4. Define Resources and Methods

Under your newly created API, click on "Actions" and choose "Create Resource". Define a resource name, for example, "movies". Once created, click on the resource and choose "Create Method". Select "GET" for fetching data and "POST" for adding data.

For GET method, choose "Integration type" as "AWS Service" and select "DynamoDB" as the integration point. Configure the integration to interact with your DynamoDB table.

GET Method Configuration

For POST method, choose "Integration type" as "Lambda Function" (or "AWS Service" if you prefer using DynamoDB directly), and configure it to interact with your DynamoDB table to add new movie details.

POST Method Configuration

5. Deploy API

After configuring resources and methods, click on "Actions" and choose "Deploy API". Select a deployment stage (e.g., "Prod") and click on "Deploy". Make note of the provided API endpoint URL, which will be used to access your API.

API Deployment

6. Test Endpoints

Use tools like Postman or cURL to test your API endpoints. For GET method, send a request to the endpoint URL to fetch movie details. For POST method, send a request with JSON payload containing movie details to add new entries to the DynamoDB table.

Testing GET Request
Testing POST Request

Conclusion

By following the above steps, you have successfully created an API Gateway integrated with DynamoDB to manage movie details. This setup provides a scalable and efficient way to push and fetch data, allowing seamless interaction between your application and the database.

Reference