如何配置AWS S3以允许POST像GET一样工作 [英] How to configure AWS S3 to allow POST to work like GET

查看:452
本文介绍了如何配置AWS S3以允许POST像GET一样工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook在其画布设置文档中声明:

Facebook states in their canvas setup documentation:

我们的服务器将对此网址发出HTTP POST请求.这 检索到的结果将显示在画布"框架中 Facebook.

Our servers will make an HTTP POST request to this web address. The retrieved result will be displayed within the Canvas frame on Facebook.

我的应用程序使用以下CORS配置作为静态网站托管在AWS S3上:

My application is hosted on AWS S3 as a static website using the following CORS configuration:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

我已经在这里遇到问题了. GET请求可以正常工作,但是POST可以访问 http ://my-bucket-name.s3-website-us-east-1.amazonaws.com 回弹:

Already I'm having an issue here. GET requests work perfectly, but POSTing to http://my-bucket-name.s3-website-us-east-1.amazonaws.com kicks back:

<html>
    <head>
        <title>405 Method Not Allowed</title>
    </head>
    <body>
        <h1>405 Method Not Allowed</h1>
        <ul>
            <li>Code: MethodNotAllowed</li>
            <li>Message: The specified method is not allowed against this resource.</li>
            <li>Method: POST</li>
            <li>ResourceType: OBJECT</li>
            <li>RequestId: 94159551A72424C7</li>
            <li>HostId: +Lcz+XaAzL97Y47OZFvaTwqz4Z7r5koaJGHjZJBBMOTUHyThTfKbZG6IxJtYEbtsXWcb/bFxeI8=</li>
        </ul>
        <hr/>
    </body>
</html>

第1步:^我想我需要使这一工作正常进行.

Step 1: ^ I think I need to get this this working.

但是等等,还有更多

Facebook还需要一个安全网址.所以为此,我去了云端.

Facebook also requires a secure url. so for this, I went to cloudfront.

我的配置如下:

就像直接使用S3一样,向 https://app- cloudfront-id.cloudfront.net/的工作原理类似于POST,可以消除以下问题:

Just like when working with S3 directly, making GET requests to https://app-cloudfront-id.cloudfront.net/ works like a champ, POSTing, kicks back this:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>MethodNotAllowed</Code>
    <Message>The specified method is not allowed against this resource.</Message>
    <Method>POST</Method>
    <ResourceType>OBJECT</ResourceType>
    <RequestId>657E87A80AFBB3B0</RequestId>
    <HostId>SY2g4smvhr06kAAQYVMsYeQZ+pSKbIIvsh/OaPBiMADGt5UKut0sXSZkFsnFmcRXQ2PFBVgPK4M=</HostId>
</Error>

在facebook.com上查看该应用程序将显示:

Viewing the app on facebook.com shows:

我想念什么吗?

推荐答案

所以-我也认为这应该很容易并且在2016年得到AWS的良好支持.显然,从我所做的所有阅读中,我们错了.

so - I too thought this should be easy and well supported by AWS in 2016. Apparently, from all the reading I've done, we're wrong.

无法通过s3为s3中的Facebook应用提供索引页面-有无Cloudfront.

There's no way to serve the index page for a facebook app from s3 - with or without cloudfront.

也许可以通过cloudfront和s3的其他源从备用源(即,您自己的httpd在某处运行)提供索引页-但我没有尝试深入研究这个兔子洞.而且,如果您仍然必须运行自己的HA httpd,那么根据资产规模而定,复杂性可能不值得.即 http ://www.bucketexplorer.com/documentation/cloudfront--how-to-create-distributions-post-distribution-with-multiple-origin-servers.html

It might be possible to serve the index page from an alternate origin (ie, your own httpd running somewhere) through cloudfront and everything else from s3 - but I haven't tried to dig into that rabbit hole. And if you're still having to run your own HA httpd...the complexity might not be worth it depending on your asset scale. ie http://www.bucketexplorer.com/documentation/cloudfront--how-to-create-distributions-post-distribution-with-multiple-origin-servers.html

您可以在提供静态内容的原始httpd前面使用cloudfront来利用缓存和边缘分布的优势-它只会将POST(和PUT等)转发到您的原始位置,并绕过缓存边缘.

you -can- use cloudfront in front of your own origin httpd serving the static content to take advantage of the cache and edge distribution - it will just forward the POST (and PUT etc) to your origin and bypass the cache edge.

这些答案很旧,大约在2011年,但我找不到任何证据证明此事发生了任何变化.

these answers are old, circa 2011, - but I can't find any evidence that anything has changed with this.

https://forums.aws.amazon.com/thread .jspa?messageID = 228988𷹼

https://forums.aws.amazon.com/thread.jspa? threadID = 62525

希望我们可以在此线程上进行一些活动来证明我错了,我现在也可以使用它.

Hopefully we can get some activity on this thread to prove me wrong, I could use this right now too.

这篇关于如何配置AWS S3以允许POST像GET一样工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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