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.

已提問 6 個月前檢視次數 203 次
1 個回答
1
已接受的答案

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
已回答 6 個月前
  • 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!

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南