配置Cloudformation以使用Cloudfront和S3将对GET / subdirectory的请求提供给/subdirectory/index.html

问题描述 投票:0回答:1

我有一个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

但是我在Property TemplateURL cannot be empty.上收到错误AWS::CloudFormation::Stack

我有一个Cloudformation模板,用于设置AWS :: CloudFront :: Distribution和AWS :: S3 :: Bucket。不幸的是,对GET / subdirectory的请求响应为403。如何配置...

amazon-web-services amazon-s3 amazon-cloudformation amazon-cloudfront aws-sam
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.