Home > Software design >  The parameter groupName cannot be used with the parameter subnet. Creating load balanced EC2 instanc
The parameter groupName cannot be used with the parameter subnet. Creating load balanced EC2 instanc

Time:11-17

i am pretty new to CloudFormation templates. I have already created a VPC with 2 public and 4 private subnets. Now, i want to create an EC2 instance in 2 of the private subnets, which is then load balanced using ELB created on a public subnet. Below is the CFT template for the same.

Parameters:
 SecurityGroupDescription:
   Description: Security Group Description
   Type: String
 KeyName:
   Description: Key Pair for EC2
   Type: 'AWS::EC2::KeyPair::KeyName'
 VPC:
   Description: Select VPC.
   Type: AWS::EC2::VPC::Id
 Subnet1:
   Description: Private Subnet to Deploy Docker MFA.
   Type: AWS::EC2::Subnet::Id
 Subnet2:
   Description: Private Subnet to Deploy Docker MFA.
   Type: AWS::EC2::Subnet::Id
Mappings:
 RegionMap:
   us-west-2:
     AMI: ami-0c54e4ec017b92f04

Resources:
 EC2InstanceMule1:
   Type: AWS::EC2::Instance
   Properties:
     InstanceType: t2.micro
     ImageId: 
       Fn::FindInMap:
       - RegionMap
       - Ref: AWS::Region
       - AMI
     SubnetId:
         Ref: Subnet1
     SecurityGroups:
       - !GetAtt EC2SecurityGroup.GroupId
     KeyName: !Ref KeyName

 EC2InstanceMule2:
   Type: AWS::EC2::Instance
   Properties:
     InstanceType: t2.micro
     ImageId: 
       Fn::FindInMap:
       - RegionMap
       - Ref: AWS::Region
       - AMI
     SubnetId:
         Ref: Subnet2
     SecurityGroups:
       - !GetAtt EC2SecurityGroup.GroupId
     KeyName: !Ref KeyName
         
 # security group
 ELBSecurityGroup:
   Type: AWS::EC2::SecurityGroup
   Properties:
     GroupDescription: ELB Security Group
     VpcId: !Ref VPC
     SecurityGroupIngress:
     - IpProtocol: tcp
       FromPort: 80
       ToPort: 80
       CidrIp: 0.0.0.0/0

 EC2SecurityGroup:
   Type: AWS::EC2::SecurityGroup
   Properties:
     GroupDescription: !Ref SecurityGroupDescription
     VpcId: !Ref VPC
     SecurityGroupIngress:
     - IpProtocol: tcp
       FromPort: 80
       ToPort: 80
       SourceSecurityGroupId: 
         Fn::GetAtt:
         - ELBSecurityGroup
         - GroupId
     - IpProtocol: tcp
       FromPort: 22
       ToPort: 22
       CidrIp: 0.0.0.0/0

 # Load Balancer for EC2
 LoadBalancerforEC2:
   Type: AWS::ElasticLoadBalancing::LoadBalancer
   Properties:
     Instances:
     - !Ref EC2InstanceMule1
     - !Ref EC2InstanceMule2
     Listeners:
     - LoadBalancerPort: '80'
       InstancePort: '80'
       Protocol: HTTP
     HealthCheck:
       Target: HTTP:80/
       HealthyThreshold: '3'
       UnhealthyThreshold: '5'
       Interval: '30'
       Timeout: '5'
     SecurityGroups:
       - !GetAtt ELBSecurityGroup.GroupId

I am getting the following error : The parameter groupName cannot be used with the parameter subnet (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterCombination

I have gone through the previous question of the same error and used the security group ID that is being created. Still the error persists. Also, any other modifications required would be appreciated.

CodePudding user response:

You should be using SecurityGroupIds, rather then SecurityGroups.

  • Related