Start free trial

Central data platform for your serverless environment.

Get full access to all premium features for 14 days. No code changes and no credit card required.

By signing up, you agree to our Privacy policy and Terms.

Using API Gateway to run Database Queries


The most common integration type for AWS API Gateway is with Lambda functions. The API service can integrate with virtually any other service that accepts HTTP requests, though. This opens up possibilities to use the API Gateway as a proxy to database queries, without any compute layer such as a Lambda function.

Why integrate API Gateway directly to a database

The direct integration between API and database is perfect when Lambda serves only as an intermediator. It can improve performance and reduce costs by removing the – sometimes unnecessary – compute layer provided by Lambda.

In the case of a DynamoDB table, AWS already exposes HTTP endpoints that clients could use to run queries. Still, API Gateway offers several advantages:

Reduced coupling between clients and database

This helps meet the fundamental black-box principle for serverless architectures. Your application clients should not know that DynamoDB is the database serving the requests. The lower coupling makes it easier to introduce changes later while avoiding unwanted side-effects.

Simplified access management and authentication

API Gateway makes it quite simple to control the authentication and authorization processes. If your application uses Cognito, it can be used seamlessly with API Gateway, for example.

Possibility to customize the HTTP methods and endpoints

The DynamoDB API endpoints might not be as user friendly as you would like for your clients. Using API Gateway allows us to accept requests in a different format and “translate” them to the DynamoDB API and query model. Analogously, it is possible to modify DynamoDB responses before returning to the client.

Throttling API requests

To avoid abuse and DDoS attacks, you can use the API Gateway embedded throttling mechanism.

Restrict which parts of the database can be accessed and by who

Since the API request and response can have the method, endpoint, and body fully customized in API Gateway, it is possible to restrict the datasets clients can access in your DynamoDB tables.

How to Integrate API Gateway and DynamoDB

API Gateway offers several different integration types. As mentioned above, the “AWS Proxy” with Lambda is the most common one. To integrate API Gateway with a DynamoDB table, for example, we will need the more general-purpose integration type, “AWS Service Proxy“.

There is a great tutorial provided by AWS on how to set up this integration for POST and GET requests.

In case you are looking to learn more about serverless architectural patterns, API Gateway, Lambda. and DynamoDB, you might want to check out this Cloud Knowledge Base.


Made by Engineers for Engineers

Our history and present are deeply rooted in building large-scale cloud applications on state-of-the-art technology. Dashbird was born out of our own need and we take pride in being developers.

Trusted by hundreds

Gus Gordon

Dashbird helped us refine the size of our Lambdas, resulting in significantly reduced costs. We have Dashbird alert us in seconds via email when any of our functions behaves abnormally. Their app immediately makes the cause and severity of errors obvious.

Read our blog

The Ultimate Guide to AWS Step Functions

The use of serverless computing has become a must nowadays, and some of you may already know a thing or two about Amazon Web Services like Lambda Functions, Step Functions, and other services AWS provides. However, if this is the first time you hear about them – fantastic!

In this article, we’ll discuss AWS Step Functions, what they are used for, how to use them, and the advantages or disadvantages that they bring.

Best Practices For Logging In AWS Lambda

We cover the best practices when logging within AWS Lambda. Explaining how and why these ways will simplify your AWS Lambda logging.


Create your first website with serverless in 15 minutes

Alright, we talked the “serverless is awesome” talk but now it’s about time to walk the walk. In the light of us launching our brand new website, we thought it would be fun to show you how to create a serverless website from scratch. In the next 15 minutes, we’ll take you through the entire process of creating your first website running on serverless and you better believe it’s going to be awesome.

The Complete AWS Lambda Handbook for Beginners (Part 3)

Welcome to the final installment of our Complete AWS Lambda Handbook series! In part three of our series, we’ll cover Lambda deployment limitations, deployment package testing, cold starts, as well as observability, debugging, and monitoring AWS Lambda.


The Ultimate Guide to AWS DynamoDB

AWS DynamoDB changed the database game in Serverless and continues to do so, as its design repeatedly proves its huge value. In this post, you’ll find out everything you need to know to get started with DynamoDB.