value of property security group must be of type list of string

Viewed 1163
Parameters:
  KeyName:
    Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
    Type: 'AWS::EC2::KeyPair::KeyName'
    ConstraintDescription: must be the name of an existing EC2 KeyPair.

  MySubnet:
    Description: My subnet from my VPC
    Type: 'AWS::EC2::Subnet::Id'
    Default: subnet-YYYYYYYY
  
  MySG:
    Description: My Security Group from my VPC
    Type: 'AWS::EC2::SecurityGroup::GroupName'
    Default: SG-YYYYYYYY
   
Resources:

  Ec2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      ImageId: ami-09e67e426f25ce0d7

      SecurityGroups: !Ref MySG

      SubnetId: !Ref MySubnet
      
      KeyName: !Ref KeyName
  
      

I have this above cloudformation template code which returns "Value of property SecurityGroups must be of type List of String", my vpc and security groups are simplified in a different cloudformation template, and i want to launch an ec2 in a specific Security group.

1 Answers

SecurityGroups must be a list of string, as the error says. So the correct template would be:

Resources:

  Ec2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      ImageId: ami-09e67e426f25ce0d7
      SecurityGroups: 
        - !Ref MySG
      SubnetId: !Ref MySubnet
      KeyName: !Ref KeyName
  
Related