Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to query an Amazon RDS instance directly from API Gateway?

Tags:

I'm new to API Gateway, and as far I have tried is a really powerful tool. For the project I'm working right now we are using a PostgreSQL instance in RDS. I've seen that is possible to access directly to DynamoDB tables from API Gateway, so I was wondering if is there a way to do so for relational databases. So I created a resource with a GET method and configure it to connect to my database, but I wasn't sure if I used the right parameters:

Provided information about the target backend

So I wasn't sure about the arguments in each setting's field. In AWS Subdomain I wrote the public URL as if I was connecting me from my pgAdmin client (no port cause the full structure was not accepted, so I know I'm doing something bad). Before that I tried using the ARN of my RDS resource, but an this error appeared:

AWS ARN for integration must contains path or action 

For execution role I created one with the policies to access my Postgres resource.

Reading RDS documentation I found out that is possible to use the Query API from RDS using the HTTP verb GET or POST and a Query parameter named Action, so I tried to figure out how to place my query statement in this way:

HTTP Query-based requests

But when I test the method, this is the Response Body:

{   "message": "AWS ARN for integration contains invalid action" } 

And this is these are the Logs:

Execution log for request test-request Sat Mar 19 15:27:17 UTC 2016 : Execution failed: AWS ARN for integration contains invalid action Sat Mar 19 15:27:17 UTC 2016 : Method completed with status: 400 

I know I'm doing a lot of things wrong, so does anybody knows if this is actually possible and how to do it, cause I haven't found any detailed tutorial yet.

like image 802
Camilo Ortegón Avatar asked Mar 19 '16 15:03

Camilo Ortegón


People also ask

How do I query AWS RDS database?

Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/ . In the navigation pane, choose Databases to display a list of your DB instances. Choose the name of the DB instance to display its details.

Can Lambda query RDS?

Lambda can work seamlessly with RDS instances, as long as you remember the specific requirements for this particular setup. Since RDS instances are running in your VPC and Lambda by default does not have access to those resources, you'll need to configure the VPC connection when creating a Lambda function.


1 Answers

No this isn't possible. The API Gateway service proxy will only proxy calls to the AWS API. The RDS API only allows you to do things like create a database, delete a database, take snapshots, etc. It doesn't allow you to connect and run queries against the database.

You should look into pointing API Gateway at a Lambda function that has the ability to connect to your RDS database and run queries.

like image 74
Mark B Avatar answered Oct 03 '22 03:10

Mark B