Is it not possible to create a AmazonMQ broker and a EC2 SecurityGroup in the same cloud formation?

0

I have the following cloud formation:

Resources:
  ActiveMQSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Security Group for Amazon MQ that allows traffic for all supported protocols and GUI access.
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 61616
          ToPort: 61616
          CidrIp: 0.0.0.0/0
          Description: OpenWire

  MyBroker:
    Type: AWS::AmazonMQ::Broker
    DependsOn: ActiveMQSecurityGroup
    Properties:
      AutoMinorVersionUpgrade: true
      BrokerName: MyBroker
      DeploymentMode: SINGLE_INSTANCE
      EngineType: ACTIVEMQ
      EngineVersion: 5.17.6
      HostInstanceType: mq.t3.micro
      PubliclyAccessible: true
      SecurityGroups:
        - !Ref ActiveMQSecurityGroup
      Logs:
        Audit: true
        General: true
      Users:
          -
            Username: '{{resolve:secretsmanager:MQSecret:SecretString:username}}'
            Password: '{{resolve:secretsmanager:MQSecret:SecretString:password}}'
            ConsoleAccess: true
            Groups:
              - admin

But I get an error saying that the security group does not exists. If I look in the console I can see that the security group was indeed created before the broker. Also if I leave the SecurityGroups out, everything is created and the broker is connected to the default security group. My understanding was that DependsOn (and implicitly via !Ref) would solve this kinda issue.

1 Respuesta
1
Respuesta aceptada

Hi,

If you are using the default VPC, you can try to explicitly mention the VPCId of the default VPC in the Security Group configuration.
Something like this:

ActiveMQSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Security Group for Amazon MQ that allows traffic for all supported protocols and GUI access.
      VpcId: "vpc-012345678abc12de3f"
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 61616
          ToPort: 61616
          CidrIp: 0.0.0.0/0
          Description: OpenWire

I tried making this change and it did not give any error, successfully deploying the cloudformation stack and MQ Broker.

Outputs

CloudformationOutput MQOutput

I hope this resolves the issue.

Thanks,
Atul

profile picture
respondido hace 6 meses
  • Huh, it works! But I have to admit the error was very vague... And the docs says Required: Conditional on the VpcId for AWS::EC2::SecurityGroup. Anyways - thank you!

  • Glad that it helped!

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas