I am trying to deploy an EC2 instance using Cloudformation but getting the following error:
No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC
despite having the vpc explicitly set on the security group:
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupName": "SG-AD-TSDB",
"GroupDescription" : "Enable SSH access via port 22",
"VpcId": "vpc-<private>",
"SecurityGroupIngress" : [ {
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : { "Ref" : "SSHLocation"}
} ]
}
}
I have no clue what to do with this error.
4
Answers
I believe
GroupName
is legacy prop used for old-fashion VPC. Just delete it, name field in SG listing seems to be copied fromGroupDescription
in my cloud.I got the same error.
I don’t know the real reason, though removing the default VPC and recreating it solved the issue in my case.
If you cannot remove the default VPC, then you should use Admin account to do that.
As Marcin commented, I believe the problem is in the
AWS::EC2::Instance
declaration. I also had this error and only after addingSubnetId
property to theNetworkInterfaces
property of the instance I succeed to deploy the stack without errors. I added this property after I had encountered this clarification.The full yaml code is:
The original code (without the SubnetId declaration) has taken from here. Note that even the original code does not include any
GroupName
declaration I had exactly the same error.While deleting just provide the Security group Id.
GroupName (string) — [EC2-Classic, default VPC] The name of the security group. You can specify either the security group name or the security group ID. For security groups in a nondefault VPC, you must specify the security group ID.
For reference see below is example, (Example 3 is for successful deletion)
Reference:
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.delete_security_group