4

这篇文章之后,我尝试在 AWS 中提供来自多个区域(在同一域下)的静态内容。

到目前为止,我有:

  • 将我的内容上传到 S3 存储桶
  • 为该存储桶启用“静态网络托管”
  • 并公开
  • 在 CloudFront 中创建了一个以 S3 存储桶为源的分配
  • 在 Route 53 中创建了一个指向分布的记录集

在这一点上,一切正常。如果我在浏览器中输入域名,我可以看到静态内容。现在是时候让它多区域了:

  • 按照文章中的说明创建一个 lambda 函数,角色持有AdministratorAccess策略(出于绝望 - 一旦我让它工作,我会仔细设计适当的角色)
  • 将 lambda 函数链接到 CloudFront:Event type: origin-request, Include body: No, Path pattern: *
  • 编辑 CloudFront 分配,添加标头X-DNS-ORIGIN

应用这些步骤后,我必须等待一分钟才能生效。一旦它们生效,我就无法再打开网页了。这样做会导致此错误消息:

503 ERROR
The request could not be satisfied.
The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions. 
If you received this error while trying to use an app or access a website, please contact the provider or website owner for assistance. 
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by following steps in the CloudFront documentation (http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/http-503-service-unavailable.html). 
Generated by cloudfront (CloudFront)

我什至启用了 CloudFront 的日志记录机制。但这也无济于事。日志只显示有一个LambdaExecutionError. 但它并没有说任何有用的东西。

我相信 lambda 函数根本没有被调用,因为我在 CloudWatch 中没有看到为它生成的任何日志。在这一点上,我不知道如何解决这个问题。任何帮助表示赞赏。

[编辑]

我忘了提。分配给 lambda 函数的角色在其信任关系选项卡lambda.amazonaws.com中具有edgelambda.amazonaws.com并列为服务。

4

1 回答 1

10

已经几个月了,但万一其他人和我一样遇到同样的问题。这篇文章很有帮助:https ://hackernoon.com/postcards-from-lambda-the-edge-11a43f215dc1

当您的代码在边缘运行时,日志记录发生在该边缘服务器的 CloudWatch 区域中。日志可能不在您认为的位置。

要查找您的日志,请在边缘服务器的区域中查找它们。就我而言,CloudWatch > 日志组 > /aws/lambda/us-east-1.lambdafunctionname

于 2019-08-01T21:26:54.247 回答