CloudFormation 未知标签 !<!Cidr>

CloudFormation unknown tag !<!Cidr>

我正在尝试使用 Amazon CloudFormation 构建 VPC 和子网,但在尝试使用 !Cidr function to specify the CidrBlock of the subnets.

时我一直 运行 遇到问题

最小示例,我使用的 CF 模板直接来自 Amazon 文档中的 !Cidr 函数。我将它保存到一个文件中,创建一个新堆栈,选择加载到该文件中,然后在 Designer 中查看。我收到此错误:

Cannot render the template because of an error.: YAMLException: unknown tag !<!Cidr> at line 18, column 75: ... Att ExampleVpc.CidrBlock, 1, 8 ]] ^

这是我正在使用的模板:

AWSTemplateFormatVersion: "2010-09-09"
Description: "Try to create VPC and Subnet using Cidr function"
Resources:
  ExampleVpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: "10.0.0.0/16"
  IPv6CidrBlock:
    Type: AWS::EC2::VPCCidrBlock
    Properties:
      AmazonProvidedIpv6CidrBlock: true
      VpcId: !Ref ExampleVpc
  ExampleSubnet:
    Type: AWS::EC2::Subnet
    DependsOn: IPv6CidrBlock
    Properties:
      AssignIpv6AddressOnCreation: true
      CidrBlock: !Select [ 0, !Cidr [ !GetAtt ExampleVpc.CidrBlock, 1, 8 ]]
      Ipv6CidrBlock: !Select [ 0, !Cidr [ !Select [ 0, !GetAtt ExampleVpc.Ipv6CidrBlocks], 1, 64 ]]
      VpcId: !Ref ExampleVpc

是我的模板有问题,还是 CloudFormation Template Designer 有问题?

您必须重新组织 模板。 Designer 语法分析器一定有一些错误。这应该有效:

AWSTemplateFormatVersion: "2010-09-09"
Description: "Try to create VPC and Subnet using Cidr function"
Resources:
  ExampleVpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: "10.0.0.0/16"
  IPv6CidrBlock:
    Type: AWS::EC2::VPCCidrBlock
    Properties:
      AmazonProvidedIpv6CidrBlock: true
      VpcId: !Ref ExampleVpc
  ExampleSubnet:
    Type: AWS::EC2::Subnet
    DependsOn: IPv6CidrBlock
    Properties:
      AssignIpv6AddressOnCreation: true
      CidrBlock:
        !Select
            - 0
            - Fn::Cidr: [ !GetAtt ExampleVpc.CidrBlock, 1, 8 ]
      Ipv6CidrBlock:
        !Select
          - 0
          - Fn::Cidr: [ !Select [ 0, !GetAtt ExampleVpc.Ipv6CidrBlocks], 1, 64 ]
      VpcId: !Ref ExampleVpc