AWS API Gateway作为S3代理:PermanentRedirect错误

时间:2018-08-12 15:18:26

标签: amazon-web-services api amazon-s3 gateway

我一直遵循本指南,以创建一个API网关,该网关可以管理上传,使用请求获取和删除: URL如下: https://docs.aws.amazon.com/es_es/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html

当我从AWS控制台触发测试时,测试运行正常,但是当我使用Postman运行测试时,它们抛出错误。 当我从AWS控制台运行GET时,请看以下日志,它可以毫无问题地获取Readme.txt文件的内容(您好!)。

GET of the Readme.txt file

上述测试的相关日志:

Execution log for request 393a03c4-9bfb-11e8-9fda-dd6a7a46761a
Thu Aug 09 17:39:53 UTC 2018 : Starting execution for request: 393a03c4-9bfb-11e8-9fda-dd6a7a46761a
Thu Aug 09 17:39:53 UTC 2018 : HTTP Method: GET, Resource Path: /api-proxy/Readme.txt
Thu Aug 09 17:39:53 UTC 2018 : Method request path: {item=Readme.txt, folder=api-proxy-s3}
Thu Aug 09 17:39:53 UTC 2018 : Method request query string: {}
Thu Aug 09 17:39:53 UTC 2018 : Method request headers: {}
Thu Aug 09 17:39:53 UTC 2018 : Method request body before transformations: 
Thu Aug 09 17:39:53 UTC 2018 : Endpoint request URI: https://s3-us-west-1.amazonaws.com/api-proxy/Readme.txt
Thu Aug 09 17:39:53 UTC 2018 : Endpoint request headers: {Authorization=***************************************************************************************************************************************************************************************************************************************************************************************4e096d, X-Amz-Date=20180809T173953Z, x-amzn-apigateway-api-id=8ep2m70f1f, Accept=application/json, x-amz-acl=authenticated-read, User-Agent=AmazonAPIGateway_8ep2m70f1f, X-Amz-Security-Token=AgoGb3JpZ2luECUaCXVzLWVhc3QtMSKAAmRO5jAPljRfWR8X0t09jgsJe91ulKpKk8qE23OQ7R0Ku6xYbUtcUQVb0Fu6okIGERYa5R8YFnmx2YXFwMcyBZqRzDAsxZoLwYyRC4c63l6Bk5dNW97E65w1SQPs7PyOL2eNRUFAHd3v1qALaeKf4+3CHMv+cYnFw/c2RhV7puaPzC2o56XmgXT+DWePSE4k92mHUzoimcYO2pJERfGvN2iHvOd4FYylP11Sv1j5qiKFDXInjPmQ2Jz+17X+XtzEYIRBkKBawP+3GADSoSkBBvAo4GKnvhEd2ndmONtOoFCmaOsE2DmlmBI+B+i2LlHYDnzte2JqInk6et22CFyR454qgAIIGxAAGgw4ODEyNDA4NDA3NDUiDNM1KM0PrpqSfQm/+CrdAYv2ry+7dec8aru/JU4L6GojMIi7+AWX+ivpw11ro2QqrGPPktb0P7v++LGc8Q3S7CntxdKsXLJPIB+6x+KLDOyMVl [TRUNCATED]
Thu Aug 09 17:39:53 UTC 2018 : Endpoint request body after transformations: 
Thu Aug 09 17:39:53 UTC 2018 : Sending request to https://s3-us-west-1.amazonaws.com/api-proxy/Readme.txt
Thu Aug 09 17:39:53 UTC 2018 : Received response. Integration latency: 499 ms
Thu Aug 09 17:39:53 UTC 2018 : Endpoint response body before transformations: Hello!
Thu Aug 09 17:39:53 UTC 2018 : Endpoint response headers: {Accept-Ranges=bytes, Server=AmazonS3, ETag="952d2c56d0485958336747bcdd98590d", x-amz-request-id=0C9D491C80DA24C6, Last-Modified=Tue, 31 Jul 2018 18:53:36 GMT, x-amz-id-2=27ZA/t75IBPzqIkZPgUy5zlDSGIlHA4MCgEi04QvG8y30tDQjfRzghSu80VZ+4zlsp+fANeN/P8=, Content-Length=6, Date=Thu, 09 Aug 2018 17:39:54 GMT, Content-Type=application/json}
Thu Aug 09 17:39:53 UTC 2018 : Method response body after transformations: Hello!
Thu Aug 09 17:39:53 UTC 2018 : Method response headers: {X-Amzn-Trace-Id=Root=1-5b6c7c69-d8140bc99bef6e0f492767bf, Content-Type=application/json}
Thu Aug 09 17:39:53 UTC 2018 : Successfully completed execution
Thu Aug 09 17:39:53 UTC 2018

现在,当我使用POSTMAN运行相同的测试时,就会出现问题:

Test using POSTMAN

响应返回:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>PermanentRedirect</Code>
    <Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message>
    <Bucket>api-proxy</Bucket>
    <Endpoint>api-proxy.s3.amazonaws.com</Endpoint>
    <RequestId>6843821F441AD6C4</RequestId>
    <HostId>NzTCXS7jTGNn5bIBIG1rNUgButeXNbWMCrwbBJklP7SldjU1/bJpeU+XKSRR3zrIkWXOU0gHyUw=</HostId>
</Error>

我检查了API日志,并得到以下信息:

(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Verifying Usage Plan for request: 3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd. API Key: API Stage: 8ep2m70f1f/staging
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) API Key authorized because method 'GET /{folder}/{item}' does not require API Key. Request will not contribute to throttle or quota limits
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Usage Plan check succeeded for API Key and API Stage 8ep2m70f1f/staging
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Starting execution for request: 3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) HTTP Method: GET, Resource Path: /api-proxy-s3/Readme.txt
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Method request path: {item=Readme.txt, folder=api-proxy-s3}
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Method request query string: 
{}
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Method request headers: {Accept=*/*, User-Agent=PostmanRuntime/7.2.0, X-Forwarded-Proto=https, X-Forwarded-For=190.133.125.248, Host=8ep2m70f1f.execute-api.us-east-1.amazonaws.com, Postman-Token=9420462e-a5e2-4450-9194-ab1f198e4456, cache-control=no-cache, X-Forwarded-Port=443, accept-encoding=gzip, deflate, X-Amzn-Trace-Id=Root=1-5b6c7e1a-2979c0c13527fa1a64f07265}
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Method request body before transformations: 
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Endpoint request URI: **https://s3-external-1.amazonaws.com/api-proxy/Readme.txt**
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Endpoint request headers: {Authorization=***************************************************************************************************************************************************************************************************************************************************************************************56f421, X-Amz-Date=20180809T174706Z, x-amzn-apigateway-api-id=8ep2m70f1f, Accept=application/json, x-amz-acl=authenticated-read, User-Agent=AmazonAPIGateway_8ep2m70f1f, X-Amz-Security-Token=AgoGb3JpZ2luECYaCXVzLWVhc3QtMSKAAkYkLaA92j0wIzzxZTf/iivp0+yQ/rwdxxMBbV1tyE3bG5qHDOjpRIOy2kGmzqoGqNVr1IAEr/22JSP3HXb8/Ggnv/HwXRiCPyzHj0gdO2QcLeoqS7arAhWfnPcXob2WzSOHAZYYqKTN9puoWysaWAnvf/qE2XiEb+00ITZ+2Mr309GQsSkEubWIAIYGajCzfn2yXkuIkeIpoiaLyriNqEdyPsGA732Z6kLW5Rp46UNB0L/v9ab5gKd0ZRcFgCDXPUBservUddFXKE13St2fCKBPWGHI75GCivH4ySS4mKfk9g7qbPgoRpEa0Hs0avW+vL6PVtflGOKJDLXhT4YLa70qgAIIGxAAGgw4ODEyNDA4NDA3NDUiDLojEuxFSmCBFSMTBSrdAZqwyTmiPyRu5VDmj6iJC5ODuJyRq5o/jO1YW5p8MO1bovvK5+DhIzVj7RExEjEvad1BoaaAhyCU6GU29BQZSqmHAu [TRUNCATED]
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Endpoint request body after transformations: 
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) **Sending request to https://s3-external-1.amazonaws.com/api-proxy/Readme.txt**
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Received response. Integration latency: 1 ms
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Endpoint response body before transformations: <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><Bucket>api-proxy-s3</Bucket><Endpoint>api-proxy.s3.amazonaws.com</Endpoint><RequestId>6843821F441AD6C4</RequestId><HostId>NzTCXS7jTGNn5bIBIG1rNUgButeXNbWMCrwbBJklP7SldjU1/bJpeU+XKSRR3zrIkWXOU0gHyUw=</HostId></Error>
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Endpoint response headers: {Transfer-Encoding=chunked, Server=AmazonS3, x-amz-request-id=6843821F441AD6C4, x-amz-id-2=NzTCXS7jTGNn5bIBIG1rNUgButeXNbWMCrwbBJklP7SldjU1/bJpeU+XKSRR3zrIkWXOU0gHyUw=, x-amz-bucket-region=us-west-1, Date=Thu, 09 Aug 2018 17:47:06 GMT, Content-Type=application/xml}
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Method response body after transformations: <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><Bucket>api-proxy-s3</Bucket><Endpoint>api-proxy.s3.amazonaws.com</Endpoint><RequestId>6843821F441AD6C4</RequestId><HostId>NzTCXS7jTGNn5bIBIG1rNUgButeXNbWMCrwbBJklP7SldjU1/bJpeU+XKSRR3zrIkWXOU0gHyUw=</HostId></Error>
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Method response headers: {X-Amzn-Trace-Id=Root=1-5b6c7e1a-2979c0c13527fa1a64f07265, Content-Type=application/json}
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Successfully completed execution
(3b783ec4-9bfc-11e8-ac4c-0dc09c2624bd) Method completed with status: 200

我们可以粗体显示该端点与通过控制台进行的测试所使用的端点不同。 对这里发生的事情有任何想法吗?也许文件有问题?与标题或集成请求中的内容有关吗?

请帮助,我不知道。

0 个答案:

没有答案