Repository: scopely-devops/skew

Issue:
Wildcard searches for ec2 instances result in exception
In version 0.16.1, when running a `skew.scan()` for a wildcard account and or region the following error is encountered:

```
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidInstanceID.NotFound) when calling the DescribeInstances operation: The instance ID <SNIP INSTANCE ID>' does not exist
```

The call for this looks like:
`skew.scan('arn:aws:ec2:*:*:instance/<SPECIFIC INSTANCE ID>')`

If I call this with the specific region and instance id, then the query succeeds. 

The full stack trace after sniping out my code lines:
```
#!/usr/bin/env python
(...)
  File "/usr/local/lib/python2.7/dist-packages/skew/arn/__init__.py", line 319, in __iter__
    for scheme in self.scheme.enumerate(context, **self.kwargs):
  File "/usr/local/lib/python2.7/dist-packages/skew/arn/__init__.py", line 244, in enumerate
    context, **kwargs):
  File "/usr/local/lib/python2.7/dist-packages/skew/arn/__init__.py", line 229, in enumerate
    context, **kwargs):
  File "/usr/local/lib/python2.7/dist-packages/skew/arn/__init__.py", line 214, in enumerate
    context, **kwargs):
  File "/usr/local/lib/python2.7/dist-packages/skew/arn/__init__.py", line 195, in enumerate
    context, **kwargs):
  File "/usr/local/lib/python2.7/dist-packages/skew/arn/__init__.py", line 146, in enumerate
    context, **kwargs):
  File "/usr/local/lib/python2.7/dist-packages/skew/arn/__init__.py", line 128, in enumerate
    self._arn, region, account, resource_id, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/skew/resources/resource.py", line 49, in enumerate
    data = client.call(enum_op, query=path, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/skew/awsclient.py", line 116, in call
    data = results.build_full_result()
  File "/usr/local/lib/python2.7/dist-packages/botocore/paginate.py", line 271, in build_full_result
    for response in self:
  File "/usr/local/lib/python2.7/dist-packages/botocore/paginate.py", line 85, in __iter__
    response = self._make_request(current_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/botocore/paginate.py", line 157, in _make_request
    return self._method(**current_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 310, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 407, in _make_api_call
    raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidInstanceID.NotFound) when calling the DescribeInstances operation: The instance ID ' <SNIP INSTANCE ID>' does not exist
```

Discussion:

Patch:
diff --git a/skew/resources/resource.py b/skew/resources/resource.py
index 93bbdf9..92514cd 100644
--- a/skew/resources/resource.py
+++ b/skew/resources/resource.py
@@ -17,6 +17,8 @@ import jmespath
 
 import skew.awsclient
 
+from botocore.exceptions import ClientError
+
 LOG = logging.getLogger(__name__)
 
 
@@ -46,7 +48,13 @@ class Resource(object):
         if extra_args:
             kwargs.update(extra_args)
         LOG.debug('enum_op=%s' % enum_op)
-        data = client.call(enum_op, query=path, **kwargs)
+        try:
+            data = client.call(enum_op, query=path, **kwargs)
+        except ClientError as e:
+            data = {}
+            # if the error is because the resource was not found, be quiet
+            if 'NotFound' not in e.response['Error']['Code']:
+                raise
         LOG.debug(data)
         resources = []
         if data:


Test patch:
diff --git a/tests/unit/responses/instances_3/ec2.DescribeInstances_1.json b/tests/unit/responses/instances_3/ec2.DescribeInstances_1.json
new file mode 100644
index 0000000..b8d59f6
--- /dev/null
+++ b/tests/unit/responses/instances_3/ec2.DescribeInstances_1.json
@@ -0,0 +1,13 @@
+{
+    "status_code": 400, 
+    "data": {
+        "ResponseMetadata": {
+            "HTTPStatusCode": 400, 
+            "RequestId": "c54d7e0e-ccfc-4a93-a2e5-862de7716e5d"
+        }, 
+        "Error": {
+            "Message": "The instance ID 'i-eedf6728' does not exist", 
+            "Code": "InvalidInstanceID.NotFound"
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/unit/test_arn.py b/tests/unit/test_arn.py
index fcbd8b4..8522ffd 100644
--- a/tests/unit/test_arn.py
+++ b/tests/unit/test_arn.py
@@ -67,6 +67,17 @@ class TestARN(unittest.TestCase):
         r = l[0]
         self.assertEqual(r.filtered_data, 't2.small')
 
+    def test_ec2_instance_not_found(self):
+        placebo_cfg = {
+            'placebo': placebo,
+            'placebo_dir': self._get_response_path('instances_3'),
+            'placebo_mode': 'playback'}
+        arn = scan('arn:aws:ec2:us-west-2:123456789012:instance/i-87654321',
+                   **placebo_cfg)
+        # Fetch all Instance resources
+        l = list(arn)
+        self.assertEqual(len(l), 0)
+
     def test_ec2_volumes(self):
         placebo_cfg = {
             'placebo': placebo,