创建一个地理匹配的 AWS WAF condition/rule 并使用 CloudFormation 将其连接到现有的 CloudFront 分配

Create a geomatching AWS WAF condition/rule and connect it to an existing CloudFront distribution using CloudFormation

简而言之,我试图完成的是以下内容:

这似乎很简单,可以在 Web 控制台中进行设置,但 CloudFormation API 似乎更受限制?

我能够很好地部署 "WAFRegional" GeoMatchSetRuleWebACL。然后,当尝试将它与现有的 CloudFront 分配相关联时,我想使用的似乎不是 "WAFRegional" 类型,而只是 "WAF" 类型。但是 "WAF"?

没有 GeoMatchSet API
AWSTemplateFormatVersion: 2010-09-09
Resources:
  # Match Sets
  GeoMatchSetWhitelist:
    Type: "AWS::WAFRegional::GeoMatchSet"
    Properties:
      Name: "GeoMatchSet for whitelist countries"
      GeoMatchConstraints:
        -
          Type: "Country"
          Value: "CA"
        -
          Type: "Country"
          Value: "US"
  ByteMatchSetLoginURIs:
    Type: "AWS::WAFRegional::ByteMatchSet"
    Properties:
      Name: "ByteMatchSet for Login URIs"
      ByteMatchTuples:
        -
          FieldToMatch:
            Type: "URI"
          TargetString: "/my/uri"
          TextTransformation: "NONE"
          PositionalConstraint: "EXACTLY"

  # Rules
  WhitelistRule:
    Type: "AWS::WAFRegional::Rule"
    Properties:
      Name: "WhitelistRule"
      MetricName: "WhitelistRule"
      Predicates:
        -
          DataId:
            Ref: "GeoMatchSetWhitelist"
          # True here means match everying NOT in this match set
          Negated: true
          Type: "GeoMatch"
        -
          DataId:
            Ref: "ByteMatchSetLoginURIs"
          Negated: false
          Type: "ByteMatch"

  # Web Access Control Lists
  WebACL:
    Type: "AWS::WAFRegional::WebACL"
    Properties:
      Name: "WhitelistWebACL"
      DefaultAction:
        Type: "ALLOW"
      MetricName: "WebACL"
      Rules:
        -
          Action:
            Type: "BLOCK"
          Priority: 2
          RuleId:
            Ref: "WhitelistRule"

  # Web ACL Association
  WebACLAssociation:
    Type: "AWS::WAF::WebACLAssociation"
    Properties:
      ResourceArn:
        Ref: "arn:aws:cloudfront::999999999999:distribution/AAAAAAAAAAAA"
      WebACLId:
        Ref: "WebACL"

运行 上面的代码给我错误 An error occurred (ValidationError) when calling the CreateChangeSet operation: Template format error: Unresolved resource dependencies [arn:aws:cloudfront::999999999999:distribution/AAAAAAAAAAAA] in the Resources block of the template.

最后,是否可以使用具有 GeoMatchSetByteMatchSet 和现有 CloudFront 分布的 CloudFormation 来构建它?

我上次检查时,CloudFormation 对 GeoMatchSet 的支持确实存在于区域,但不存在于全球 (CloudFront)。不幸的是,CloudFormation 以功能支持的大杂烩而闻名,尽管它正在慢慢变得更好...