【发布时间】:2020-03-04 13:14:03
【问题描述】:
我有一个 Cloudformation 模板,用于设置 AWS::CloudFront::Distribution 和 AWS::S3::Bucket。不幸的是,对 GET /subdirectory 的请求以 403 响应。如何配置 Cloudformation 模板以让 GET /subdirectory 服务 /subdirectory/index.html?
我的 Cloudfront 配置如下:
CloudFrontDistribution:
Type: 'AWS::CloudFront::Distribution'
Properties:
DistributionConfig:
Aliases:
- !FindInMap [Domain, !Ref Stage, Domain]
ViewerCertificate:
AcmCertificateArn: !Ref Cert
SslSupportMethod: sni-only
CustomErrorResponses:
- ErrorCode: 403 # not found
ResponseCode: 404
ResponsePagePath: !Ref ErrorPagePath
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
CachedMethods:
- GET
- HEAD
- OPTIONS
Compress: true
DefaultTTL: 3600 # in seconds
ForwardedValues:
Cookies:
Forward: none
QueryString: false
MaxTTL: 86400 # in seconds
MinTTL: 60 # in seconds
TargetOriginId: s3origin
ViewerProtocolPolicy: redirect-to-https
DefaultRootObject: !Ref DefaultRootObject
Enabled: true
HttpVersion: http2
Origins:
- DomainName: !GetAtt 'S3Bucket.DomainName'
Id: s3origin
S3OriginConfig:
OriginAccessIdentity: !Sub 'origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}'
PriceClass: 'PriceClass_All'
除了对 GET /subdirectory 的请求之外,一切正常。
我也试过了:
- DomainName: !GetAtt 'S3Bucket.RegionalDomainName'
Id: s3origin
S3OriginConfig:
OriginProtocolPolicy: http-only
但是我在AWS::CloudFormation::Stack 上收到了错误Property TemplateURL cannot be empty.。
【问题讨论】:
-
看来我需要为重写规则设置一个 Lambda@Edge 函数。 aws.amazon.com/blogs/networking-and-content-delivery/…我还不确定如何使用 Cloudformation 来实现这一点,但我会在进行研究后跟进...
标签: amazon-web-services amazon-s3 amazon-cloudformation amazon-cloudfront aws-sam