繁体   English   中英

如何在现有 su.net 或我创建的 su.net 模板中指定 su.netID?

[英]How do I specify subnetID in cloudformation template, either from existing subnet or one that I create?

如何在现有 su.net 或我创建的 YAML cloudformation 模板中指定 su.netID?

我不断收到堆栈错误,它需要是一个字符串或以下内容。

2022-04-18 19:56:17 UTC+1000 DBInstance CREATE_FAILED 参数groupName不能与参数su.net一起使用(服务:AmazonEC2;状态码:400;错误码:InvalidParameterCombination;请求ID:45b4589e-0195-4f13 -9cde-d2200c0031bf;代理:空)

--- 
Parameters:
  AvailabilityZone:
    Type: String
    Default: us-east-1a

  EnvironmentInstanceType:
    Description: "Specify the Environment type of the stack."
    Type: String
    Default: Web
    AllowedValues:
      - Web
      - DB

  KeyName:
    Description: Saved Key Pair file for SSH Access
    Type: AWS::EC2::KeyPair::KeyName

  VpcId:
    Description: Select your VPC
    Type: AWS::EC2::VPC::Id

  ImageId:
    Description: GoldenAMI ImageId
    Type: String
    Default: ami-06170cf892b466b5a

  PrivSubnetCIDR:
    Description: Private Subnet CidrBlock
    Type: String
    Default: 10.0.1.0/24

  PublicSecurityGroup:
    Description: WebSecurityGroup
    Type: String
    Default: sg-081d3059c58edb3b6

  PublicSubnet:
    Description: Web/PublicSecurityGroup
    Type : String
    Default: subnet-0b3ea12c33b327f0a





Mappings:
  EnvironmentToInstanceType:
   Web:
     InstanceType: t2.micro
DB:
  InstanceType: t2.micro




Resources:

 DBSubnet:
Type: AWS::EC2::Subnet
Properties:
  VpcId: !Ref VpcId
  AvailabilityZone: !Select [ 0, !GetAZs '' ]
  CidrBlock: !Ref PrivSubnetCIDR
  MapPublicIpOnLaunch: false
  
DBInstance:
Type: AWS::EC2::Instance
Properties:
  KeyName:
    Ref: KeyName
  InstanceType:
    !FindInMap [
      EnvironmentToInstanceType,
      !Ref EnvironmentInstanceType,
      InstanceType,
    ]
  ImageId: !Ref ImageId
  AvailabilityZone: !Ref AvailabilityZone
  SubnetId:
         Ref: DBSubnet
  SecurityGroups: [!Ref DBSecurityGroup]
  
     
DBSecurityGroup: 
Type: AWS::EC2::SecurityGroup
Properties:
  GroupDescription: "Open MySQL (port 3306)"
  VpcId:
    Ref: VpcId
 
    
DBOutboundRule1:
Type: AWS::EC2::SecurityGroupEgress
Properties:
    GroupId: !Ref DBSecurityGroup
    IpProtocol: tcp
    FromPort: 22
    ToPort: 22
    SourceSecurityGroupId: !Ref PublicSecurityGroup

DBInboundRule1:
Type: AWS::EC2::SecurityGroupEgress
Properties:
    GroupId: !Ref DBSecurityGroup
    IpProtocol: tcp
    FromPort: 3306
    ToPort: 3306
    SourceSecurityGroupId: !Ref PublicSecurityGroup
 
  

      
DBRouteTable:
Type: AWS::EC2::RouteTable
Properties:
  VpcId: !Ref VpcId
   
DBSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
  RouteTableId: !Ref DBRouteTable
  SubnetId: !Ref DBSubnet


WebInstance: 
Type: AWS::EC2::Instance
Properties:
  KeyName:
    Ref: KeyName
  InstanceType:
    !FindInMap [
      EnvironmentToInstanceType,
      !Ref EnvironmentInstanceType,
      InstanceType,
    ]
  ImageId: !Ref ImageId
  # AvailabilityZone: !Ref AvailabilityZone
  SubnetId: !Ref PublicSubnet
  SecurityGroupIds:
        - Ref: PublicSecurityGroup

该错误与 su.nets 无关,但与您的安全组有关。 代替:

SecurityGroups: [!Ref DBSecurityGroup]

它应该是:

SecurityGroupIds: [!GetAtt DBSecurityGroup.GroupId]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM