云形成模板错误

Cloud Formation Template errors

我开始学习 Cloud Formation 模板,当我在 AWS Cloud Formation -> 创建新堆栈中验证模板时,我 运行 遇到了问题。我正在 Pycharm 中使用 CloudFormation 插件编写模板。这些是我在 CloudFormation 中验证时收到的几条错误消息:

1/10/2022,5:41:06 PM - 模板包含错误。:模板格式错误:YAML 格式不正确。 (第 27 行,第 16 列)

1/10/2022,5:40:06 PM - 模板包含错误。:模板格式错误:YAML 格式不正确。 (第 24 行,第 12 列)

下面是我的简单代码:

AWSTemplateFormatVersion: "2010-09-09"
# Description:
Resources:
  #Create the VPC
  MyCustomVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: '10.3.0.0/16'
      EnableDnsHostnames: true
      EnableDnsSupport: true
      Tags:
        - key: Name
          value: !Sub '${AWS::StackName}-application-vpc-acg'
  # Create the Subnets
  PublicSubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: '10.3.0.0/24'
      MapPublicIpOnLaunch: false
      AvailabilityZone: !Select [ 0, !GetAZs]
      Tags:
        - Key: Name
          Value: !Sub '${AWS::StackName}-public-subnet-A'
      VpcId: !Ref MyCustomVPC


  PublicSubnetB:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: '10.3.1.0/24'
      MapPublicIpOnLaunch: false
      AvailabilityZone: !Select [1, !GetAz]
      Tags:
        - Key: Name
          Value: !Sub '${AWS::StackName}-public-subnet-B'
      VpcId: !Ref MyCustomVPC

  #Create Internet Gateway
  MyInternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - key: Name
          Value: !Sub '${AWS::StackName}-Internet-Gateway

  #Attach Internet Gateway to VPC
  MyIGWAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      InternetGatewayId: !Ref MyInternetGateway
      VpcId: !Ref MyCustomVPC

非常感谢任何帮助我指明正确方向的人。 谢谢!

存在许多问题,例如拼写错误、缺少括号、函数错误。正确的版本是:

AWSTemplateFormatVersion: "2010-09-09"
# Description:
Resources:
  #Create the VPC
  MyCustomVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: '10.3.0.0/16'
      EnableDnsHostnames: true
      EnableDnsSupport: true
      Tags:
        - Key: Name
          Value: !Sub '${AWS::StackName}-application-vpc-acg'
  # Create the Subnets
  PublicSubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: '10.3.0.0/24'
      MapPublicIpOnLaunch: false
      AvailabilityZone: !Select [ 0, !GetAZs ""]
      Tags:
        - Key: Name
          Value: !Sub '${AWS::StackName}-public-subnet-A'
      VpcId: !Ref MyCustomVPC


  PublicSubnetB:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: '10.3.1.0/24'
      MapPublicIpOnLaunch: false
      AvailabilityZone: !Select [1, !GetAZs ""]
      Tags:
        - Key: Name
          Value: !Sub '${AWS::StackName}-public-subnet-B'
      VpcId: !Ref MyCustomVPC

  #Create Internet Gateway
  MyInternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: !Sub '${AWS::StackName}-Internet-Gateway'

  #Attach Internet Gateway to VPC
  MyIGWAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      InternetGatewayId: !Ref MyInternetGateway
      VpcId: !Ref MyCustomVPC