我正在使用https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/static-site AWS cdk示例来配置Cloudfront + S3存储桶以为静态站点提供服务。
虽然看起来对GET / subdirectory的请求不会以/subdirectory/index.html进行响应。一个人将如何使用cdk将Cloudfront + S3配置为服务/subdirectory/index.html?
我正在使用https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/static-site AWS cdk示例来配置Cloudfront + S3存储桶以为静态站点提供服务。
虽然看起来对GET / subdirectory的请求不会以/subdirectory/index.html进行响应。一个人将如何使用cdk将Cloudfront + S3配置为服务/subdirectory/index.html?
如果您不想使用 lambda,您可以将错误重定向到 index.html,这是您应该使用
在 CloudFront 上托管 SPA 的方式errorConfigurations: [
{
errorCode: 403,responseCode: 200,responsePagePath: '/index.html',errorCachingMinTtl: 10
}
]
,
最后我找到了创建Lambda @ Edge函数的解决方案,该函数执行了Url Rewrite。
https://briantakita.com/posts/static-https-websites-using-aws-cdk-cloudfront-and-s3
源代码包含在此gist中。