参数groupName不能与参数子网一起使用

问题描述 投票:0回答:1
AWSTemplateFormatVersion: 2010-09-09
Parameters:
  MyKeyName:
    Description: Select the key name from the list
    Type: AWS::EC2::KeyPair::KeyName
  Instancetypes:
    Type: String
    AllowedValues:
    - t2.micro
    - t2.nano

Resources:
  myEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      KeyName: !Ref MyKeyName  
      ImageId: ami-0323c3dd2da7fb37d
      InstanceType: !Ref Instancetypes
      SecurityGroupIds:
        - default        
        - !Ref SSHSecurityGroup
      SubnetId: !Ref subnet1
      Tags:
        - Key: Name 
          Value: EC2

  SSHSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties: 
      GroupDescription: my new SSH security group
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '22'
          ToPort: '22'
          CidrIp: 0.0.0.0/0
      VpcId: !Ref LocalVPC

  LocalVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsSupport: true

  subnet1:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-east-1a
      VpcId: !Ref LocalVPC
      CidrBlock: 10.0.1.0/24

  subnet2:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-east-1b
      VpcId: !Ref LocalVPC
      CidrBlock: 10.0.2.0/24

  subnet3:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-east-1c
      VpcId: !Ref LocalVPC
      CidrBlock: 10.0.3.0/24

  routeTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId:
        Ref: LocalVPC

  routeName:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref routeTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref igwName

  routeTableAssocName:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref subnet1
      RouteTableId: !Ref routeTable

  igwName:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: keyname
          Value: valuea

  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref LocalVPC
      InternetGatewayId: !Ref igwName

enter image description here

amazon-web-services amazon-cloudformation
1个回答
0
投票

SecurityGroupIds使用一个Group ID,而不是一个Group Name:

  SecurityGroupIds:
    - !GetAtt SSHSecurityGroup.GroupId
© www.soinside.com 2019 - 2024. All rights reserved.