【问题标题】:S3 Redirection Rules for API Gateway not workingAPI 网关的 S3 重定向规则不起作用
【发布时间】:2018-12-16 19:56:07
【问题描述】:

我正在关注 this tutorial 并创建 LambdaAPI GatewayS3 bucket

已完成 Lambda 和 Api 网关的集成并记录日志。 我面临的问题是在 S3 存储桶中无法访问 Api Gaetway。

我在属性中启用Use this bucket to host a website 并为索引文档添加index.html

重定向规则是

<RoutingRules>
<RoutingRule>
<Condition>
  <KeyPrefixEquals/>
  <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
  <Protocol>https</Protocol>
  <HostName>xyz.execute-api.ap-south-1.amazonaws.com</HostName>
  <ReplaceKeyPrefixWith>prod/api</ReplaceKeyPrefixWith>
  <HttpRedirectCode>307</HttpRedirectCode>
</Redirect>

当我点击那里不存在的 s3 存储桶图像时,它应该点击此 API 网关并登录 Cloudwatch 但它没有发生。

如果我直接点击 APIGaetway 网址,它会记录

【问题讨论】:

  • 这可能不是构建此集成的最佳方式,但请尝试将 &lt;HttpErrorCodeReturnedEquals&gt; 设置为 403,而不是 404。
  • @Michael-sqlbot 没有影响
  • 如果它不起作用,它实际上是做什么的?有错误吗?

标签: amazon-web-services amazon-s3 aws-lambda aws-api-gateway amazon-cloudwatch


【解决方案1】:

请尝试在 API 网关中启用 CORS。选项的PFB。

  1. 转到 API 网关 2.选择您的 API,当它在资源选项卡中时,转到操作下拉菜单并
  2. 选择“启用 CORS”并点击“启用 Cors 并替换现有的 CORs 标头”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    相关资源
    最近更新 更多