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!

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容