You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CloudFormation模板格式错误:AWS::EC2::Route的YAML语法问题

CloudFormation模板格式错误修复

核心错误点

  • 第30行的AddInternetGatewayRouteToRouteTable资源名称后缺少冒号,违反YAML键值对的语法规则,这是导致格式报错的直接原因。
  • 额外小问题:MyInternetGateway的Tags中错误使用了Name字段,正确的标签键值对需用Key和Value,此处需修正为Value: Test。

修复后的完整模板

AWSTemplateFormatVersion: 2010-09-09
Description: VPC, Subnets and EC2
Resources:
  MyVpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 192.168.0.0/16
      EnableDnsHostnames: true
      Tags:
         -
           Key: Stack
           Value: Test
  MyVpcRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref MyVpc
  MyInternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
         -
            Key: Stack
            Value: Test
  AddInternetGatewayToVpc:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      InternetGatewayId: !Ref MyInternetGateway
      VpcId: !Ref MyVpc
  AddInternetGatewayRouteToRouteTable:
      Type: AWS::EC2::Route
      Properties:
        GatewayId: !Ref MyInternetGateway
        DestinationCidrBlock: 0.0.0.0/0
        RouteTableId: !Ref MyVpcRouteTable
  PublicSubnet:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVpc
      CidrBlock: 192.168.1.0/24
      MapPublicIpOnLaunch: true
      AvailabilityZoneId: euw1-az2
  PrivateSubnet:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVpc
      CidrBlock: 192.168.2.0/24
      MapPublicIpOnLaunch: false
      AvailabilityZoneId: euw1-az2
  WebserverInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0ea0f26a6d50850c5
      InstanceType: t2.micro
      SubnetId: !Ref PublicSubnet
      KeyName: !Ref MyInstanceKeyPair
  MyInstanceKeyPair:
    Type: AWS::EC2::KeyPair
    Properties:
      KeyName: MyKeyPair

内容的提问来源于stack exchange,提问作者Scofield

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 21:40:27