VPC错误:模板的“资源”块中的未解决资源依赖项[VPC]

时间:2020-07-01 17:58:07

标签: amazon-web-services amazon-cloudformation amazon-vpc subnet

我正在使用cloudformation创建一个vpc,但是在运行它时显示了错误。我已经创建了具有Internet网关和2个子网的vpc,一个是公共的,另一个是私有的,但是当我将yaml文件上传到cloudformation时,它显示以下错误 我的yml文件:

---
Description: An AWS VPC with two subnets.
AWSTemplateFormatVersion: 2010-09-09
Resources:
  myVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 11.0.0.0/16
      EnableDnsSupport: true
      EnableDnsHostnames: true
      InstanceTenancy: default
  InternetGateway:
    Type: AWS::EC2::InternetGateway
  VPCGatewayAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref myVPC
      InternetGatewayId: !Ref InternetGateway
  SubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-east-2a
      VpcId: !Ref myVPC
      CidrBlock: 11.0.1.0/24
      MapPublicIpOnLaunch: true
  SubnetB:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-east-2a
      VpcId: !Ref myVPC
      CidrBlock: 11.0.0.0/24
      MapPublicIpOnLaunch: false
  RouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref myVPC
  InternetRoute:
    Type: AWS::EC2::Route
    DependsOn: VPCGatewayAttachment
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway
      RouteTableId: !Ref RouteTable
  SubnetARouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref RouteTable
      SubnetId: !Ref SubnetA
  SubnetBRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref RouteTable
      SubnetId: !Ref SubnetB
  SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupName: "Internet Group"
      GroupDescription: "SSH traffic in, all traffic out."
      VpcId: !Ref myVPC
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: "22"
          ToPort: "22"
          CidrIp: 0.0.0.0/0
      SecurityGroupEgress:
        - IpProtocol: -1
          CidrIp: 0.0.0.0/0
  InstanceSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow http to client host
      VpcId: !Ref myVPC
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0
      SecurityGroupEgress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0

  RDSSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow http to client host
      VpcId: !Ref myVPC

  RDSSecurityGroupIngress:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !Ref RDSSecurityGroup
      IpProtocol: tcp
      FromPort: 3306
      ToPort: 3306
      SourceSecurityGroupId: !Ref InstanceSecurityGroup

  myDBSubnetGroup:
    Type: "AWS::RDS::DBSubnetGroup"
    Properties:
      DBSubnetGroupDescription: "description"
      SubnetIds:
        - !Ref SubnetB

  wahajwebserver:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0bdcc6c05dec346bf
      InstanceType: t2.micro
      KeyName: wahaj(webserver)
      SubnetId:
        Ref: SubnetA
      SecurityGroupIds: [!Ref InstanceSecurityGroup]

  wahajdbRDS:
    Type: AWS::RDS::DBInstance
    Properties:
      AllocatedStorage: 20
      AvailabilityZone: us-east-2c
      DBInstanceClass: db.t2.micro
      DBInstanceIdentifier: wahajwebserver
      DBName: wahajdb
      DBSubnetGroupName: !Ref myDBSubnetGroup
      DeleteAutomatedBackups: true
      Engine: MySQL
      MasterUsername: wahajdb
      MasterUserPassword: wahajdb
      VPCSecurityGroups: [!Ref RDSSecurityGroup]

我尝试在cli中使用validate函数,但错误相同,无法找出错误。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

您对gcloud app deploy的引用应为!Ref VPC!Ref myVPC期望存在名为!Ref VPC的参数或资源,您已将VPC资源命名为VPC

myVPC