The parameter groupName cannot be used with the parameter subnet

518 views
Skip to first unread message

Anup Singh

unread,
Mar 22, 2018, 1:04:02 PM3/22/18
to cloudtools-dev
Hi All, 

I am getting following error when creating my first EC2 instance 

SecurityGroup Code:
sg = ec2.SecurityGroup(self.SG_Name)
sg.GroupDescription = self.SG_Description
sg.VpcId = 'vpc-c55a12ab'#Ref('DefaultVPC')
sg_array = []
for sg_name in self.SG_Defination:
sg_array.append(ec2.SecurityGroupRule(IpProtocol=self.SG_Defination[sg_name]['protocol'],
FromPort=self.SG_Defination[sg_name]['FromPort'],
ToPort=self.SG_Defination[sg_name]['ToPort'],
CidrIp=self.SG_Defination[sg_name]['CidrIp']))

sg.SecurityGroupIngress = sg_array

Error: The parameter groupName cannot be used with the parameter subnet
instance = ec2.Instance(instance_name)
instance.ImageId = instance_ami_name
instance.InstanceType = instance_type
instance.SecurityGroups = ['sg-b7e777em']#[Ref(instance_sg)]
instance.KeyName = Ref('InstanceKeyName')
instance.IamInstanceProfile = IAMProfile
instance.SubnetId = 'subnet-12345a12'
self.template.add_resource(instance)
return self.template

when I remove the Subnet I get the following Error: 

Error: No default VPC for this user

instance = ec2.Instance(instance_name)
instance.ImageId = instance_ami_name
instance.InstanceType = instance_type
instance.SecurityGroups = ['sg-b3e12345']#[Ref(instance_sg)]
instance.KeyName = Ref('InstanceKeyName')
instance.IamInstanceProfile = IAMProfile
#instance.SubnetId = 'subnet-556a123'
self.template.add_resource(instance)
return self.template

Anup Singh

unread,
Mar 22, 2018, 1:33:48 PM3/22/18
to cloudtools-dev
Resolved it, We must use SecurityGroupIds instead of SecurityGroups 

Following would be the code:
instance = ec2.Instance(instance_name)
instance.ImageId = instance_ami_name
instance.InstanceType = instance_type
instance.SecurityGroupIds = [Ref(instance_sg)]

instance.KeyName = Ref('InstanceKeyName')
instance.IamInstanceProfile = IAMProfile
instance.SubnetId = Ref('MySubnetId')
self.template.add_resource(instance)
return self.template
Reply all
Reply to author
Forward
0 new messages