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.


Read our blog

ANNOUNCEMENT: new pricing and the end of free tier

Today we are announcing a new, updated pricing model and the end of free tier for Dashbird.

4 Tips for AWS Lambda Performance Optimization

In this article, we’re covering 4 tips for AWS Lambda optimization for production. Covering error handling, memory provisioning, monitoring, performance, and more.

AWS Lambda Free Tier: Where Are The Limits?

In this article we’ll go through the ins and outs of AWS Lambda pricing model, how it works, what additional charges you might be looking at and what’s in the fine print.

Made by developers for developers

Dashbird was born out of our own need for an enhanced serverless debugging and monitoring tool, and we take pride in being developers.

What our customers say

Dashbird gives us a simple and easy to use tool to have peace of mind and know that all of our Serverless functions are running correctly. We are instantly aware now if there’s a problem. We love the fact that we have enough information in the Slack notification itself to take appropriate action immediately and know exactly where the issue occurred.

Thanks to Dashbird the time to discover the occurrence of an issue reduced from 2-4 hours to a matter of seconds or minutes. It also means that hundreds of dollars are saved every month.

Great onboarding: it takes just a couple of minutes to connect an AWS account to an organization in Dashbird. The UI is clean and gives a good overview of what is happening with the Lambdas and API Gateways in the account.

I mean, it is just extremely time-saving. It’s so efficient! I don’t think it’s an exaggeration or dramatic to say that Dashbird has been a lifesaver for us.

Dashbird provides an easier interface to monitor and debug problems with our Lambdas. Relevant logs are simple to find and view. Dashbird’s support has been good, and they take product suggestions with grace.

Great UI. Easy to navigate through CloudWatch logs. Simple setup.

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.