是否可以直接从API Gateway查询Amazon RDS实例? [英] Is it possible to query an Amazon RDS instance directly from API Gateway?

查看:133
本文介绍了是否可以直接从API Gateway查询Amazon RDS实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是API Gateway的新手,到目前为止,我已经尝试了一个非常强大的工具.对于我现在正在工作的项目,我们在RDS中使用PostgreSQL实例.我已经看到可以从API Gateway直接访问DynamoDB表,所以我想知道是否有一种方法可以用于关系数据库.因此,我使用GET方法创建了一个资源,并将其配置为连接到数据库,但是我不确定是否使用了正确的参数:

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:

提供的有关目标后端的信息

所以我不确定每个设置字段中的参数.在AWS Subdomain中,我编写了公共URL,就好像我是从pgAdmin客户端连接我一样(没有端口,因为不接受完整结构,所以我知道我做的不好).在此之前,我尝试使用RDS资源的ARN,但是出现了此错误:

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

对于执行角色,我使用访问我的Postgres资源的策略创建了一个.

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

阅读RDS文档后,我发现可以使用HTTP动词GET或POST和名为Action的Query参数从RDS使用Query API,所以我试图弄清楚如何以这种方式放置查询语句:

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查询的请求

但是当我测试该方法时,这是响应主体:

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

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

这是这些日志:

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.

推荐答案

不可能. API Gateway服务代理将仅代理对AWS API的调用. RDS API仅允许您执行诸如创建数据库,删除数据库,创建快照等操作.不允许使用RDS API来对数据库进行连接和运行查询.

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.

您应该考虑将API网关指向Lambda函数,该函数可以连接到RDS数据库并运行查询.

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

这篇关于是否可以直接从API Gateway查询Amazon RDS实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆