Skip to content

Can API Gateway directly integrate with RDS (without Lambda)? Example/tutorial please

0

Could use help from #AWS gurus here!

API Gateway integration request with AWS Service dropdown shows RDS - but, havent seen any tutorial (Asked AmazonQ to help - but it said NOT possible without Lambda) to describe if it is possible to directly integrate APIGateway with RDS. Is it possible to do CRUD with an RDS DIRECTLY - without Lambda? ( I know API Gateway can directly integrate with DynamoDB)

2 Answers
1
Accepted Answer

Hello.

This function is not for viewing database data in RDS, but for performing RDS operations (such as DescribeDBInstances) using the AWS API.
AWS publishes APIs for operating AWS resources, but depending on the programming language, SDKs may not be available, making it difficult to execute the API.
In such cases, publishing the API with API Gateway makes it simple to execute the API.
Therefore, you cannot perform CRUD directly.
You will need Lambda or similar to perform CRUD.
https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-aws-proxy.html

Both the Tutorial: Create a REST API with a Lambda proxy integration and Tutorial: Create a REST API with a Lambda non-proxy integration topics describe how to create an API Gateway API to expose the integrated Lambda function. In addition, you can create an API Gateway API to expose other AWS services, such as Amazon SNS, Amazon S3, Amazon Kinesis, and even AWS Lambda. This is made possible by the AWS integration. The Lambda integration or the Lambda proxy integration is a special case, where the Lambda function invocation is exposed through the API Gateway API.

All AWS services support dedicated APIs to expose their features. However, the application protocols or programming interfaces are likely to differ from service to service. An API Gateway API with the AWS integration has the advantage of providing a consistent application protocol for your client to access different AWS services.

EXPERT

answered a year ago

EXPERT

reviewed 2 months ago

  • Thank you Riku! Wish AWS would better-explain the list of services in the Integration section to reduce the confusion for people like me! Some document that describes what can/cannot be achieved by each service integration could help!

-1

API Gateway cannot directly integrate with RDS without using Lambda as an intermediary. While API Gateway does offer direct integrations with some AWS services (like DynamoDB, S3, and Firehose) through AWS service proxies, RDS is not one of them.

The reason for this limitation is that RDS requires SQL queries to interact with its databases, and API Gateway doesn't have built-in capability to translate REST API calls into SQL queries. Additionally, RDS databases typically reside in private VPCs and require proper authentication mechanisms.

For connecting to RDS, you would need to use a Lambda function as an intermediary that:

  1. Handles the connection to the RDS database
  2. Executes the appropriate SQL queries
  3. Returns the results to API Gateway

When using Lambda with RDS, AWS recommends using RDS Proxy in production environments, especially for applications that generate a large number of connections in a short period. RDS Proxy manages a pool of shared database connections, enabling your function to reach high concurrency levels without exhausting database connections. For Lambda functions that are executed infrequently (e.g., once every hour), connecting directly from Lambda to RDS might be acceptable.

If you're looking to reduce operational overhead and Lambda costs, you should consider direct integrations where they are available, but for RDS interactions, a Lambda function is necessary.
Sources
Which is preferred, Lambda->RDS Proxy->RDS or Lambda->RDS? | AWS re:Post
Direct integrations - Serverless Applications Lens
Set up an API integration request using the API Gateway console - Amazon API Gateway

answered a year ago

  • If bypassing Lambda is NOT possible while using RDS, wonder why RDS is listed as an integration option in API Gateway - Integration Type - AWS Service - RDS! That is the portion I'd like to understand better!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.