You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

单S3桶+CloudFront+Lambda托管多静态站点的503错误调试求助

单S3桶托管多静态站点的CloudFront 503错误调试方案

配置背景

  • S3桶My-bucket内文件夹与访问URL映射规则:
    • My-bucket/feature-abc-123 → my-url/feature-abc-123
    • My-bucket/feature-abc-456 → my-url/feature-abc-456
    • My-bucket/feature-xyz-123 → my-url/feature-xyz-123
  • 桶根目录的index.html作为my-url的默认站点页面

遇到的问题

完成配置后,访问CloudFront分配域名my-url时出现503错误:

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. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.

Generated by cloudfront (CloudFront)
Request ID: jfjdf

调试方案

1. 验证Lambda函数是否被触发

  • 查看CloudFront访问日志
    开启CloudFront访问日志后,日志中会包含x-edge-request-id和lambda-function-arn字段:若请求触发Lambda,会记录对应ARN;未触发则无该字段。
  • 查看Lambda监控指标
    进入Lambda控制台找到目标函数,查看Invocations指标:访问my-url后指标数值上升,说明函数被触发;数值无变化则未触发。
  • 检查CloudFront行为配置
    确认CloudFront分发的对应路径模式(如/*)下,已正确关联Lambda@Edge函数,且触发事件类型(如Viewer Request/Origin Request)符合配置需求。

2. 查看Lambda的输出及控制台日志

  • 查看Lambda@Edge的CloudWatch日志
    Lambda@Edge日志生成在请求触发的边缘区域(而非函数创建区域):
    1. 进入CloudWatch控制台,切换到用户访问对应的CloudFront边缘区域(如us-east-1、eu-west-1)
    2. 查找名称格式为/aws/lambda/us-east-1.<你的Lambda函数名>的日志组(即使函数创建在其他区域,边缘区域会生成独立日志)
    3. 打开对应日志流,即可查看执行日志、输出内容及错误信息
  • 手动测试Lambda函数
    在Lambda控制台创建模拟CloudFront请求的测试事件(参考Lambda@Edge触发格式),手动执行函数,直接查看控制台返回的输出与日志,验证逻辑是否正常。
  • 检查Lambda权限配置
    确认Lambda函数拥有lambda:GetFunction权限,且IAM角色信任策略包含edgelambda.amazonaws.com和cloudfront.amazonaws.com,确保CloudFront有权调用该函数。

内容的提问来源于stack exchange,提问作者margherita pizza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 13:55:02