简体   繁体   English

使用API​​网关为boto3创建端点URL

[英]Create endpoint url for boto3 using API Gateway

At the moment my application uses boto3 to access AWS resources. 目前,我的应用程序使用boto3访问AWS资源。 However I'd like to instead use the API Gateway to front the AWS Services used so that everything is funnelled through the API Gateway instead of directly to the services. 但是,我想改用API网关来管理所使用的AWS服务,以便所有内容都通过API网关传递,而不是直接传递到服务。

I have the API Gateway working, but how can I tell boto3 to use this new endpoint because the API Gateway endpoints are setup on a per action basis. 我可以使用API​​网关,但是由于API网关终结点是按操作设置的,因此如何告诉boto3使用此新终结点。 ie, there's one for ListQueues and another for CreateQueue. 即,一个用于ListQueues,另一个用于CreateQueue。

Using boto3 with the endpoint-url parameter gives me this error: 将boto3与endpoints-url参数一起使用会给我这个错误:

botocore.parsers.ResponseParserError: Unable to parse response (not well-formed (invalid token): line 1, column 0), invalid XML received: {"message":"Credential should be scoped to correct service: 'execute-api'. "} botocore.parsers.ResponseParserError:无法解析响应(格式不正确(无效令牌):第1行,第0列),收到无效的XML:{“ message”:“凭据的范围应为正确的服务:'execute-api' 。“}

When creating your client, you can pass the keyword parameter endpoint_url which lets you override the default URL botocore would construct for the target service otherwise. 创建客户端时,可以传递关键字参数endpoint_url ,该参数可以覆盖botocore否则将为目标服务构造的默认URL。

import boto3

client = boto3.client('sqs', endpoint_url="https://your.api.gateway.url.here")

You will need some management here since it sounds like you have read-only API Gateway endpoints, and then some that have write capabilities. 您在这里需要进行一些管理,因为听起来您有只读的API Gateway端点,然后又有一些具有写功能。

After doing some more research, the real answer is this is actually not possible because boto3 library does not support API Gateway as one of the services it makes available. 经过更多研究后,真正的答案是这实际上是不可能的,因为boto3库不支持API网关作为它提供的服务之一。

See here: https://github.com/boto/botocore/issues/1140 看到这里: https : //github.com/boto/botocore/issues/1140

There is currently an open feature request to allow boto3 to make calls to an API Gateway resource: https://github.com/boto/boto3/issues/1246 当前有一个开放功能请求,允许boto3调用API网关资源: https : //github.com/boto/boto3/issues/1246

If anyone knows something I don't know please let me know. 如果有人知道我不知道的事,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM