amazon-web-services - Cloudfront 与 cloudformation:AWS::CloudFront::Distribution:您的请求包含一个或多个无效位置代码

标签 amazon-web-services aws-cloudformation

尝试使用 Cloudformaton 创建此 CloudFront 发行版时,我不断收到您的请求包含一个或多个无效位置代码。错误,并且我无法弄清楚错误来自何处

下面是我的资源的副本

CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
DependsOn: ESRVApiGatewayDeployment
Properties:
  DistributionConfig:
    ViewerCertificate:
      AcmCertificateArn: !Ref ACM
      MinimumProtocolVersion: TLSv1.2_2021
      SslSupportMethod: sni-only          
      CloudFrontDefaultCertificate: 'false'
    Origins:
      - DomainName: !ImportValue FrontEndBucketWebsiteURL
        Id: !Sub '${EnvTags}-W3S3Origin'
        S3OriginConfig:
          OriginAccessIdentity: 
            !Join
              - ""
              - - 'origin-access-identity/cloudfront/'
                -  !Ref ESRVOAI
      - DomainName: !Sub "${ESRVApiGatewayDeployment}.execute-api.${AWS::Region}.amazonaws.com"
        Id: !Sub '${EnvTags}-ApiGwOrigin'
        CustomOriginConfig: 
          HTTPPort: 80
          HTTPSPort: 443
          OriginKeepaliveTimeout: 15
          OriginProtocolPolicy: 'https-only'
          OriginReadTimeout: 45
          OriginSSLProtocols: 
            - 'TLSv1.2'
        OriginCustomHeaders:
          - HeaderName: 'X-API-Key'
            HeaderValue: !Ref ApiKey
    Enabled: "true"
    DefaultRootObject: index.html
    IPV6Enabled: 'true'
    Comment: !Sub '${EnvTags}-Cloudfront distribution to distribute frontend resources from S3 bucket'
    Logging: 
      Bucket: !ImportValue LoggingBucketDNS
      Prefix: cloudfront/
      IncludeCookies: 'true'
    DefaultCacheBehavior: 
      FunctionAssociations:
        - FunctionARN: !GetAtt CloudfrontFunction.FunctionARN
          EventType: 'viewer-request'
      AllowedMethods:
        - DELETE
        - GET
        - HEAD
        - OPTIONS
        - PATCH
        - POST
        - PUT
      CachedMethods:
        - GET
        - HEAD
      TargetOriginId: !Sub '${EnvTags}-W3S3Origin'
      ResponseHeadersPolicyId: !Ref ResponseHeadersPolicy
      ForwardedValues: 
        QueryString: 'true'
        Cookies:         
          Forward: "none"
      ViewerProtocolPolicy: redirect-to-https
    CacheBehaviors:
      - 
        AllowedMethods:
          - DELETE
          - GET
          - HEAD
          - OPTIONS
          - PATCH
          - POST
          - PUT
        CachedMethods:
          - GET
          - HEAD
        Compress: 'true'
        DefaultTTL: 0
        MaxTTL: 0
        MinTTL: 0
        SmoothStreaming: 'false'
        PathPattern: !Sub
          - '/${envPath}*'
          - envPath: !Ref EnvTags
        TargetOriginId: !Sub 
          - '${EnvTags}-ApiGwOrigin'
          - EnvTags: !Ref EnvTags
        ViewerProtocolPolicy: 'https-only'
        ForwardedValues: 
          Headers: 
            - 'Authorization'
          QueryString: "true"
          Cookies:
            Forward: "none"
    CustomErrorResponses:
      - ErrorCode: 404
        ResponseCode: 200
        ResponsePagePath: /index.html
    PriceClass: 'PriceClass_All'
    Restrictions:
      GeoRestriction:
        Locations: 
          - "none"
        RestrictionType: "none"
    Aliases:
      - !Ref DomainName

我已经仔细检查以确保我拥有所有缩进权限和值正确。也许我缺少一些东西。 任何帮助将不胜感激

最佳答案

位置字段需要有一个两个字母,即您想要包含在黑名单中的国家/地区的大写国家/地区代码,或者白名单。 None 不是有效值。由于您有 RestrictionType: "none",因此未启用地理限制,这意味着对内容的访问不受客户端地理位置的限制。在这种情况下,您不需要传递 locations 字段。但是,如果您想按国家/地区限制内容的分发,您可以执行以下操作:-

Restrictions:
          GeoRestriction:
            RestrictionType: whitelist
            Locations:
            - AQ
            - CV

希望这会有所帮助。

关于amazon-web-services - Cloudfront 与 cloudformation:AWS::CloudFront::Distribution:您的请求包含一个或多个无效位置代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76043539/

相关文章:

amazon-web-services - 使用 sha1 进行 AWS S3 签名真的安全吗?

node.js - 是否可以在不使用公共(public)回调的情况下收听 AWS SNS 通知?

amazon-web-services - 无法使用云形成创建VPC和路由表

amazon-web-services - 我们如何在具有相同用户数据配置的同一模板中重用配置的 AMI

docker - CannotPullContainerError : Error response from daemon: pull access denied for ECR Repo Image, 存储库不存在或可能需要 'docker login'

amazon-web-services - 键包含点时可以设置映射吗?

ios - dynamodb,MobileHub 不工作

amazon-web-services - 如何访问Cloudformation中的跨区域资源

amazon-web-services - 我们如何对AWS CDK代码进行单元测试?我们应该吗?

amazon-web-services - 如何统计CloudFormation模板生成的资源数量?