Repository: cloud-custodian/cloud-custodian

Issue:
Amazon MQ Resource
Is there any plan to add Amazon MQ as a resource?


Discussion:

Resolving patch:
diff --git a/c7n/resources/__init__.py b/c7n/resources/__init__.py
--- a/c7n/resources/__init__.py
+++ b/c7n/resources/__init__.py
@@ -70,6 +70,7 @@ def load_resources():
     import c7n.resources.kinesis
     import c7n.resources.kms
     import c7n.resources.ml
+    import c7n.resources.mq
     import c7n.resources.opsworks
     import c7n.resources.rds
     import c7n.resources.rdsparamgroup
diff --git a/c7n/resources/mq.py b/c7n/resources/mq.py
new file mode 100644
--- /dev/null
+++ b/c7n/resources/mq.py
@@ -0,0 +1,76 @@
+# Copyright 2018 Capital One Services, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+from c7n.actions import Action
+from c7n.filters.metrics import MetricsFilter
+from c7n.filters.vpc import SecurityGroupFilter, SubnetFilter
+from c7n.manager import resources
+from c7n.query import QueryResourceManager
+from c7n.utils import local_session, type_schema
+
+
+@resources.register('message-broker')
+class MessageBroker(QueryResourceManager):
+
+    class resource_type(object):
+        service = 'mq'
+        enum_spec = ('list_brokers', 'BrokerSummaries', None)
+        detail_spec = (
+            'describe_broker', 'BrokerId', 'BrokerId', None)
+
+        id = 'BrokerId'
+        name = 'BrokerName'
+        date = None
+        dimension = 'Broker'
+        filter_name = None
+        metrics_namespace = 'AWS/AmazonMQ'
+
+
+@MessageBroker.filter_registry.register('subnet')
+class MQSubnetFilter(SubnetFilter):
+
+    RelatedIdsExpression = 'SubnetIds[]'
+
+
+@MessageBroker.filter_registry.register('security-group')
+class MQSGFilter(SecurityGroupFilter):
+
+    RelatedIdsExpression = 'SecurityGroups[]'
+
+
+@MessageBroker.filter_registry.register('metrics')
+class MQMetrics(MetricsFilter):
+
+    def get_dimensions(self, resource):
+        # Fetching for Active broker instance only, https://amzn.to/2tLBhEB
+        return [{'Name': self.model.dimension,
+                 'Value': "{}-1".format(resource['BrokerName'])}]
+
+
+@MessageBroker.action_registry.register('delete')
+class Delete(Action):
+    """Delete a set of message brokers
+    """
+
+    schema = type_schema('delete')
+    permissions = ("mq:DeleteBroker",)
+
+    def process(self, resources):
+        client = local_session(self.manager.session_factory).client('mq')
+        for r in resources:
+            try:
+                client.delete_broker(BrokerId=r['BrokerId'])
+            except client.exceptions.NotFoundException:
+                continue


Test patch:
diff --git a/tests/data/placebo/test_mq_delete/mq.DeleteBroker_1.json b/tests/data/placebo/test_mq_delete/mq.DeleteBroker_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_delete/mq.DeleteBroker_1.json
@@ -0,0 +1,23 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {
+            "RequestId": "d0021dcb-7b80-11e8-8878-71f86fe974cb",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "application/json",
+                "content-length": "53",
+                "connection": "keep-alive",
+                "date": "Fri, 29 Jun 2018 09:43:01 GMT",
+                "x-amzn-requestid": "d0021dcb-7b80-11e8-8878-71f86fe974cb",
+                "x-amz-apigw-id": "JPTNyEVOCYcF-qg=",
+                "x-amzn-trace-id": "Root=1-5b35ff25-a29f2c803782b27a9272949f",
+                "x-cache": "Miss from cloudfront",
+                "via": "1.1 52187b0c6f7878d62f08293f88e6cdd1.cloudfront.net (CloudFront)",
+                "x-amz-cf-id": "RtwmAL7kp3__8d9FFzYV_9nCeWomfVPCu0V0VBxrpP33KNI1qoyyyw=="
+            },
+            "RetryAttempts": 0
+        },
+        "BrokerId": "b-ec204b6b-2cd7-464d-98fe-d80eaf273afb"
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_mq_delete/mq.DescribeBroker_1.json b/tests/data/placebo/test_mq_delete/mq.DescribeBroker_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_delete/mq.DescribeBroker_1.json
@@ -0,0 +1,63 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {
+            "RequestId": "cfbc626b-7b80-11e8-a361-bdc527374a7d",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "application/json",
+                "content-length": "1242",
+                "connection": "keep-alive",
+                "date": "Fri, 29 Jun 2018 09:43:00 GMT",
+                "x-amzn-requestid": "cfbc626b-7b80-11e8-a361-bdc527374a7d",
+                "x-amz-apigw-id": "JPTNuGhziYcFgbQ=",
+                "x-amzn-trace-id": "Root=1-5b35ff24-0517dd87ff27c9285535b2c3",
+                "x-cache": "Miss from cloudfront",
+                "via": "1.1 91189ac49e2bc1430ae921e209fd10e9.cloudfront.net (CloudFront)",
+                "x-amz-cf-id": "y6tw3peiqxq_40sxYLgA19EL9qPx3tuWXGTvhF5mO3XeV33sqQ_QZQ=="
+            },
+            "RetryAttempts": 0
+        },
+        "AutoMinorVersionUpgrade": true,
+        "BrokerArn": "arn:aws:mq:us-east-2:644160558196:broker:dev:b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+        "BrokerId": "b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+        "BrokerInstances": [
+            {
+                "ConsoleURL": "https://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:8162",
+                "Endpoints": [
+                    "ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61617",
+                    "amqp+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:5671",
+                    "stomp+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61614",
+                    "mqtt+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:8883",
+                    "wss://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61619"
+                ]
+            }
+        ],
+        "BrokerName": "dev",
+        "BrokerState": "RUNNING",
+        "Configurations": {
+            "Current": {
+                "Id": "c-4cf667b5-6201-4625-86ac-4ff1e9b54fc2",
+                "Revision": 1
+            },
+            "History": []
+        },
+        "DeploymentMode": "SINGLE_INSTANCE",
+        "EngineType": "ActiveMQ",
+        "EngineVersion": "5.15.0",
+        "HostInstanceType": "mq.t2.micro",
+        "MaintenanceWindowStartTime": {
+            "DayOfWeek": "SUNDAY",
+            "TimeOfDay": "11:00",
+            "TimeZone": "UTC"
+        },
+        "PubliclyAccessible": true,
+        "SecurityGroups": [
+            "sg-aa6c90c3"
+        ],
+        "SubnetIds": [
+            "subnet-b77a4ffd"
+        ],
+        "Users": []
+    }
+}
diff --git a/tests/data/placebo/test_mq_delete/mq.DescribeBroker_2.json b/tests/data/placebo/test_mq_delete/mq.DescribeBroker_2.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_delete/mq.DescribeBroker_2.json
@@ -0,0 +1,63 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {
+            "RequestId": "d057b7e7-7b80-11e8-819f-7b385573b93a",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "application/json",
+                "content-length": "1242",
+                "connection": "keep-alive",
+                "date": "Fri, 29 Jun 2018 09:43:01 GMT",
+                "x-amzn-requestid": "d057b7e7-7b80-11e8-819f-7b385573b93a",
+                "x-amz-apigw-id": "JPTN4EkDiYcF9Yw=",
+                "x-amzn-trace-id": "Root=1-5b35ff25-3f11ca00fa5bf263d79455ba",
+                "x-cache": "Miss from cloudfront",
+                "via": "1.1 aacaf57a89a827fd9e2cbb6fe0d21e43.cloudfront.net (CloudFront)",
+                "x-amz-cf-id": "D7lkODE_a_XiudsvLpb90oaE2pOOfFuf9ZppMs-pb97fc_usO_5qyg=="
+            },
+            "RetryAttempts": 0
+        },
+        "AutoMinorVersionUpgrade": true,
+        "BrokerArn": "arn:aws:mq:us-east-2:644160558196:broker:dev:b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+        "BrokerId": "b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+        "BrokerInstances": [
+            {
+                "ConsoleURL": "https://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:8162",
+                "Endpoints": [
+                    "ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61617",
+                    "amqp+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:5671",
+                    "stomp+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61614",
+                    "mqtt+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:8883",
+                    "wss://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61619"
+                ]
+            }
+        ],
+        "BrokerName": "dev",
+        "BrokerState": "DELETION_IN_PROGRESS",
+        "Configurations": {
+            "Current": {
+                "Id": "c-4cf667b5-6201-4625-86ac-4ff1e9b54fc2",
+                "Revision": 1
+            },
+            "History": []
+        },
+        "DeploymentMode": "SINGLE_INSTANCE",
+        "EngineType": "ActiveMQ",
+        "EngineVersion": "5.15.0",
+        "HostInstanceType": "mq.t2.micro",
+        "MaintenanceWindowStartTime": {
+            "DayOfWeek": "SUNDAY",
+            "TimeOfDay": "11:00",
+            "TimeZone": "UTC"
+        },
+        "PubliclyAccessible": true,
+        "SecurityGroups": [
+            "sg-aa6c90c3"
+        ],
+        "SubnetIds": [
+            "subnet-b77a4ffd"
+        ],
+        "Users": []
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_mq_delete/mq.ListBrokers_1.json b/tests/data/placebo/test_mq_delete/mq.ListBrokers_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_delete/mq.ListBrokers_1.json
@@ -0,0 +1,32 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {
+            "RequestId": "cf75e35e-7b80-11e8-aa2f-196aaa6bb56b",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "application/json",
+                "content-length": "351",
+                "connection": "keep-alive",
+                "date": "Fri, 29 Jun 2018 09:43:00 GMT",
+                "x-amzn-requestid": "cf75e35e-7b80-11e8-aa2f-196aaa6bb56b",
+                "x-amz-apigw-id": "JPTNpG6jiYcFc0g=",
+                "x-amzn-trace-id": "Root=1-5b35ff24-a84853261f7cca482c8dd4b2",
+                "x-cache": "Miss from cloudfront",
+                "via": "1.1 01b00ded82405e6c5be64787abc6bcc9.cloudfront.net (CloudFront)",
+                "x-amz-cf-id": "zcitBhdtM72Q2jPgMl6LH6NQf1HGEYLPyX0MsHjsZeKRAIfg7QLOHQ=="
+            },
+            "RetryAttempts": 0
+        },
+        "BrokerSummaries": [
+            {
+                "BrokerArn": "arn:aws:mq:us-east-2:644160558196:broker:dev:b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+                "BrokerId": "b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+                "BrokerName": "dev",
+                "BrokerState": "RUNNING",
+                "DeploymentMode": "SINGLE_INSTANCE",
+                "HostInstanceType": "mq.t2.micro"
+            }
+        ]
+    }
+}
diff --git a/tests/data/placebo/test_mq_metrics/monitoring.GetMetricStatistics_1.json b/tests/data/placebo/test_mq_metrics/monitoring.GetMetricStatistics_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_metrics/monitoring.GetMetricStatistics_1.json
@@ -0,0 +1,33 @@
+{
+    "status_code": 200,
+    "data": {
+        "Label": "CpuUtilization",
+        "Datapoints": [
+            {
+                "Timestamp": {
+                    "__class__": "datetime",
+                    "year": 2018,
+                    "month": 6,
+                    "day": 28,
+                    "hour": 9,
+                    "minute": 41,
+                    "second": 0,
+                    "microsecond": 0
+                },
+                "Average": 5.522026045882309,
+                "Unit": "Percent"
+            }
+        ],
+        "ResponseMetadata": {
+            "RequestId": "98fbd099-7b80-11e8-80f8-9150c8220456",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "x-amzn-requestid": "98fbd099-7b80-11e8-80f8-9150c8220456",
+                "content-type": "text/xml",
+                "content-length": "511",
+                "date": "Fri, 29 Jun 2018 09:41:28 GMT"
+            },
+            "RetryAttempts": 0
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_mq_metrics/mq.DescribeBroker_1.json b/tests/data/placebo/test_mq_metrics/mq.DescribeBroker_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_metrics/mq.DescribeBroker_1.json
@@ -0,0 +1,67 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {
+            "RequestId": "98b8fa75-7b80-11e8-8af9-07d7321fb577",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "application/json",
+                "content-length": "1247",
+                "connection": "keep-alive",
+                "date": "Fri, 29 Jun 2018 09:41:28 GMT",
+                "x-amzn-requestid": "98b8fa75-7b80-11e8-8af9-07d7321fb577",
+                "x-amz-apigw-id": "JPS_THkyiYcFYDw=",
+                "x-amzn-trace-id": "Root=1-5b35fec8-80e1303c213278a070efde78",
+                "x-cache": "Miss from cloudfront",
+                "via": "1.1 681e14c46d92209afdcd71825174b409.cloudfront.net (CloudFront)",
+                "x-amz-cf-id": "iPP77pNV92P13B1b8z0T-unEswKXnu_KzO7D33FuqtvzfWubfdtWdA=="
+            },
+            "RetryAttempts": 0
+        },
+        "AutoMinorVersionUpgrade": true,
+        "BrokerArn": "arn:aws:mq:us-east-2:644160558196:broker:dev:b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+        "BrokerId": "b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+        "BrokerInstances": [
+            {
+                "ConsoleURL": "https://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:8162",
+                "Endpoints": [
+                    "ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61617",
+                    "amqp+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:5671",
+                    "stomp+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61614",
+                    "mqtt+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:8883",
+                    "wss://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61619"
+                ]
+            }
+        ],
+        "BrokerName": "dev",
+        "BrokerState": "RUNNING",
+        "Configurations": {
+            "Current": {
+                "Id": "c-4cf667b5-6201-4625-86ac-4ff1e9b54fc2",
+                "Revision": 1
+            },
+            "History": []
+        },
+        "DeploymentMode": "SINGLE_INSTANCE",
+        "EngineType": "ActiveMQ",
+        "EngineVersion": "5.15.0",
+        "HostInstanceType": "mq.t2.micro",
+        "MaintenanceWindowStartTime": {
+            "DayOfWeek": "SUNDAY",
+            "TimeOfDay": "11:00",
+            "TimeZone": "UTC"
+        },
+        "PubliclyAccessible": true,
+        "SecurityGroups": [
+            "sg-aa6c90c3"
+        ],
+        "SubnetIds": [
+            "subnet-b77a4ffd"
+        ],
+        "Users": [
+            {
+                "Username": "dev"
+            }
+        ]
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_mq_metrics/mq.ListBrokers_1.json b/tests/data/placebo/test_mq_metrics/mq.ListBrokers_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_metrics/mq.ListBrokers_1.json
@@ -0,0 +1,32 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {
+            "RequestId": "9872069d-7b80-11e8-a9d3-5b3a88c46dc6",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "application/json",
+                "content-length": "338",
+                "connection": "keep-alive",
+                "date": "Fri, 29 Jun 2018 09:41:27 GMT",
+                "x-amzn-requestid": "9872069d-7b80-11e8-a9d3-5b3a88c46dc6",
+                "x-amz-apigw-id": "JPS_OGDDCYcFzVw=",
+                "x-amzn-trace-id": "Root=1-5b35fec7-8052d018534f7cc85fd70f74",
+                "x-cache": "Miss from cloudfront",
+                "via": "1.1 ec34e3a999b5ec4dd8e20b1dc77e2fa1.cloudfront.net (CloudFront)",
+                "x-amz-cf-id": "r-h0ur8ENkbpuOhMnuKAAHs4_ahGMxSQHGNBQF2bBsGCpETo2WOqyg=="
+            },
+            "RetryAttempts": 0
+        },
+        "BrokerSummaries": [
+            {
+                "BrokerArn": "arn:aws:mq:us-east-2:644160558196:broker:dev:b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+                "BrokerId": "b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+                "BrokerName": "dev",
+                "BrokerState": "RUNNING",
+                "DeploymentMode": "SINGLE_INSTANCE",
+                "HostInstanceType": "mq.t2.micro"
+            }
+        ]
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_mq_query/ec2.DescribeSecurityGroups_1.json b/tests/data/placebo/test_mq_query/ec2.DescribeSecurityGroups_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_query/ec2.DescribeSecurityGroups_1.json
@@ -0,0 +1,59 @@
+{
+    "status_code": 200,
+    "data": {
+        "SecurityGroups": [
+            {
+                "Description": "default VPC security group",
+                "GroupName": "default",
+                "IpPermissions": [
+                    {
+                        "IpProtocol": "-1",
+                        "IpRanges": [],
+                        "Ipv6Ranges": [],
+                        "PrefixListIds": [],
+                        "UserIdGroupPairs": [
+                            {
+                                "GroupId": "sg-aa6c90c3",
+                                "UserId": "644160558196"
+                            }
+                        ]
+                    }
+                ],
+                "OwnerId": "644160558196",
+                "GroupId": "sg-aa6c90c3",
+                "IpPermissionsEgress": [
+                    {
+                        "IpProtocol": "-1",
+                        "IpRanges": [
+                            {
+                                "CidrIp": "0.0.0.0/0"
+                            }
+                        ],
+                        "Ipv6Ranges": [],
+                        "PrefixListIds": [],
+                        "UserIdGroupPairs": []
+                    }
+                ],
+                "Tags": [
+                    {
+                        "Key": "NetworkLocation",
+                        "Value": "Private"
+                    }
+                ],
+                "VpcId": "vpc-5f6c9936"
+            }
+        ],
+        "ResponseMetadata": {
+            "RequestId": "de1d1361-5856-46ab-bcc9-74d35f693257",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "text/xml;charset=UTF-8",
+                "transfer-encoding": "chunked",
+                "vary": "Accept-Encoding",
+                "date": "Fri, 29 Jun 2018 09:21:50 GMT",
+                "server": "AmazonEC2"
+            },
+            "RetryAttempts": 0
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_mq_query/ec2.DescribeSubnets_1.json b/tests/data/placebo/test_mq_query/ec2.DescribeSubnets_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_query/ec2.DescribeSubnets_1.json
@@ -0,0 +1,41 @@
+{
+    "status_code": 200,
+    "data": {
+        "Subnets": [
+            {
+                "AvailabilityZone": "us-east-2c",
+                "AvailableIpAddressCount": 4086,
+                "CidrBlock": "172.31.32.0/20",
+                "DefaultForAz": true,
+                "MapPublicIpOnLaunch": true,
+                "State": "available",
+                "SubnetId": "subnet-b77a4ffd",
+                "VpcId": "vpc-5f6c9936",
+                "AssignIpv6AddressOnCreation": false,
+                "Ipv6CidrBlockAssociationSet": [],
+                "Tags": [
+                    {
+                        "Key": "Name",
+                        "Value": ""
+                    },
+                    {
+                        "Key": "NetworkLocation",
+                        "Value": "Public"
+                    }
+                ]
+            }
+        ],
+        "ResponseMetadata": {
+            "RequestId": "d8a4266e-0a48-449b-aa02-b0577c5ead7c",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "text/xml;charset=UTF-8",
+                "transfer-encoding": "chunked",
+                "vary": "Accept-Encoding",
+                "date": "Fri, 29 Jun 2018 09:21:50 GMT",
+                "server": "AmazonEC2"
+            },
+            "RetryAttempts": 0
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_mq_query/mq.DescribeBroker_1.json b/tests/data/placebo/test_mq_query/mq.DescribeBroker_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_query/mq.DescribeBroker_1.json
@@ -0,0 +1,67 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {
+            "RequestId": "da4c6bfd-7b7d-11e8-90fa-29cd6ad27cbe",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "application/json",
+                "content-length": "1247",
+                "connection": "keep-alive",
+                "date": "Fri, 29 Jun 2018 09:21:49 GMT",
+                "x-amzn-requestid": "da4c6bfd-7b7d-11e8-90fa-29cd6ad27cbe",
+                "x-amz-apigw-id": "JPQHKERxCYcFcLg=",
+                "x-amzn-trace-id": "Root=1-5b35fa2d-1abf99cce0434290fcccf974",
+                "x-cache": "Miss from cloudfront",
+                "via": "1.1 edd2aa1fcea462364d4033aa6f41f580.cloudfront.net (CloudFront)",
+                "x-amz-cf-id": "7mtTV1vDmnxzoAv_FiiV7SNcUs59KLtyfdKq_rZS_MhopFINa_cOZQ=="
+            },
+            "RetryAttempts": 0
+        },
+        "AutoMinorVersionUpgrade": true,
+        "BrokerArn": "arn:aws:mq:us-east-2:644160558196:broker:dev:b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+        "BrokerId": "b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+        "BrokerInstances": [
+            {
+                "ConsoleURL": "https://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:8162",
+                "Endpoints": [
+                    "ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61617",
+                    "amqp+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:5671",
+                    "stomp+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61614",
+                    "mqtt+ssl://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:8883",
+                    "wss://b-ec204b6b-2cd7-464d-98fe-d80eaf273afb-1.mq.us-east-2.amazonaws.com:61619"
+                ]
+            }
+        ],
+        "BrokerName": "dev",
+        "BrokerState": "RUNNING",
+        "Configurations": {
+            "Current": {
+                "Id": "c-4cf667b5-6201-4625-86ac-4ff1e9b54fc2",
+                "Revision": 1
+            },
+            "History": []
+        },
+        "DeploymentMode": "SINGLE_INSTANCE",
+        "EngineType": "ActiveMQ",
+        "EngineVersion": "5.15.0",
+        "HostInstanceType": "mq.t2.micro",
+        "MaintenanceWindowStartTime": {
+            "DayOfWeek": "SUNDAY",
+            "TimeOfDay": "11:00",
+            "TimeZone": "UTC"
+        },
+        "PubliclyAccessible": true,
+        "SecurityGroups": [
+            "sg-aa6c90c3"
+        ],
+        "SubnetIds": [
+            "subnet-b77a4ffd"
+        ],
+        "Users": [
+            {
+                "Username": "dev"
+            }
+        ]
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_mq_query/mq.ListBrokers_1.json b/tests/data/placebo/test_mq_query/mq.ListBrokers_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_mq_query/mq.ListBrokers_1.json
@@ -0,0 +1,32 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {
+            "RequestId": "da0b44b5-7b7d-11e8-9a00-234143b06f52",
+            "HTTPStatusCode": 200,
+            "HTTPHeaders": {
+                "content-type": "application/json",
+                "content-length": "338",
+                "connection": "keep-alive",
+                "date": "Fri, 29 Jun 2018 09:21:49 GMT",
+                "x-amzn-requestid": "da0b44b5-7b7d-11e8-9a00-234143b06f52",
+                "x-amz-apigw-id": "JPQHGE_1CYcF5pQ=",
+                "x-amzn-trace-id": "Root=1-5b35fa2d-dece7c24cbd4018c6b698f04",
+                "x-cache": "Miss from cloudfront",
+                "via": "1.1 af15d0c5a09f1b704887eb71e3875b4c.cloudfront.net (CloudFront)",
+                "x-amz-cf-id": "_1xP5EGXWZLHlv-KsFlmnfOS2pwnfaTNGrxU_DWXUC1g8fO-XDl1Tw=="
+            },
+            "RetryAttempts": 0
+        },
+        "BrokerSummaries": [
+            {
+                "BrokerArn": "arn:aws:mq:us-east-2:644160558196:broker:dev:b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+                "BrokerId": "b-ec204b6b-2cd7-464d-98fe-d80eaf273afb",
+                "BrokerName": "dev",
+                "BrokerState": "RUNNING",
+                "DeploymentMode": "SINGLE_INSTANCE",
+                "HostInstanceType": "mq.t2.micro"
+            }
+        ]
+    }
+}
\ No newline at end of file
diff --git a/tests/test_mq.py b/tests/test_mq.py
new file mode 100644
--- /dev/null
+++ b/tests/test_mq.py
@@ -0,0 +1,77 @@
+# Copyright 2018 Capital One Services, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+
+from .common import BaseTest
+
+
+class MessageQueue(BaseTest):
+
+    def test_query_with_subnet_sg_filter(self):
+        factory = self.replay_flight_data("test_mq_query")
+        p = self.load_policy(
+            {
+                "name": "mq",
+                "resource": "message-broker",
+                "filters": [
+                    {'type': 'subnet',
+                     'key': 'tag:NetworkLocation',
+                     'value': 'Public'},
+                    {'type': 'security-group',
+                     'key': 'tag:NetworkLocation',
+                     'value': 'Private'}]
+            },
+            config={'region': 'us-east-2'},
+            session_factory=factory,
+        )
+        resources = p.run()
+        self.assertEqual(len(resources), 1)
+        self.assertEqual(resources[0]['BrokerName'], 'dev')
+
+    def test_metrics(self):
+        factory = self.replay_flight_data('test_mq_metrics')
+        p = self.load_policy(
+            {'name': 'mq-metrics',
+             'resource': 'message-broker',
+             'filters': [{
+                 'type': 'metrics',
+                 'name': 'CpuUtilization',
+                 'op': 'gt',
+                 'value': 0,
+                 'days': 1}]},
+            config={'region': 'us-east-2'},
+            session_factory=factory)
+        resources = p.run()
+        self.assertEqual(len(resources), 1)
+        self.assertEqual(resources[0]['BrokerName'], 'dev')
+        self.assertTrue('c7n.metrics' in resources[0])
+
+    def test_delete_mq(self):
+        factory = self.replay_flight_data("test_mq_delete")
+        p = self.load_policy(
+            {
+                "name": "mqdel",
+                "resource": "message-broker",
+                "filters": [{"BrokerName": "dev"}],
+                "actions": ["delete"],
+            },
+            config={'region': 'us-east-2'},
+            session_factory=factory,
+        )
+        resources = p.run()
+        self.assertEqual(len(resources), 1)
+        client = factory().client("mq")
+        broker = client.describe_broker(BrokerId='dev')
+        self.assertEqual(broker['BrokerState'], 'DELETION_IN_PROGRESS')