Repository: localstack/localstack

Issue:
`kinesis_conn` is an undefined name in aws_models.py
`kinesis_conn`is used three times in [`./localstack/utils/aws/aws_models.py`](https://github.com/localstack/localstack/blob/master/localstack/utils/aws/aws_models.py#L65-L72) but I am unable to find where it is defined.  Any ideas?

flake8 testing of https://github.com/localstack/localstack on Python 3.6.2

$ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__
```
./localstack/utils/aws/aws_models.py:65:22: F821 undefined name 'kinesis_conn'
        s_iterator = kinesis_conn.get_shard_iterator(self.stream_name, shard, 'TRIM_HORIZON')
                     ^

./localstack/utils/aws/aws_models.py:66:18: F821 undefined name 'kinesis_conn'
        record = kinesis_conn.get_records(s_iterator['ShardIterator'])
                 ^

./localstack/utils/aws/aws_models.py:72:34: F821 undefined name 'kinesis_conn'
                    next_entry = kinesis_conn.get_records(record['NextShardIterator'])
                                 ^
```



Discussion:

Resolving patch:
diff --git a/localstack/utils/aws/aws_models.py b/localstack/utils/aws/aws_models.py
--- a/localstack/utils/aws/aws_models.py
+++ b/localstack/utils/aws/aws_models.py
@@ -62,14 +62,16 @@ def put(self, data, key):
         return self.conn.put_record(StreamName=self.stream_name, Data=data, PartitionKey=key)
 
     def read(self, amount=-1, shard='shardId-000000000001'):
-        s_iterator = kinesis_conn.get_shard_iterator(self.stream_name, shard, 'TRIM_HORIZON')
-        record = kinesis_conn.get_records(s_iterator['ShardIterator'])
+        if not self.conn:
+            raise Exception('Please create the Kinesis connection first.')
+        s_iterator = self.conn.get_shard_iterator(self.stream_name, shard, 'TRIM_HORIZON')
+        record = self.conn.get_records(s_iterator['ShardIterator'])
         while True:
             try:
                 if record['NextShardIterator'] is None:
                     break
                 else:
-                    next_entry = kinesis_conn.get_records(record['NextShardIterator'])
+                    next_entry = self.conn.get_records(record['NextShardIterator'])
                     if len(next_entry['Records']):
                         print(next_entry['Records'][0]['Data'])
                     record = next_entry


Test patch:
diff --git a/tests/integration/test_cloudformation.py b/tests/integration/test_cloudformation.py
--- a/tests/integration/test_cloudformation.py
+++ b/tests/integration/test_cloudformation.py
@@ -1,5 +1,6 @@
 import os
 import yaml
+import unittest
 from localstack.utils.aws import aws_stack
 from localstack.utils.common import load_file, retry
 from localstack.utils.cloudformation import template_deployer
@@ -41,42 +42,42 @@ def get_stack_details(stack_name):
             return stack
 
 
-def test_apply_template():
-    cloudformation = aws_stack.connect_to_resource('cloudformation')
-    template = template_deployer.template_to_json(load_file(TEST_TEMPLATE_1))
+class CloudFormationTest(unittest.TestCase):
 
-    # deploy template
-    cloudformation.create_stack(StackName=TEST_STACK_NAME, TemplateBody=template)
+    def test_apply_template(self):
+        cloudformation = aws_stack.connect_to_resource('cloudformation')
+        template = template_deployer.template_to_json(load_file(TEST_TEMPLATE_1))
 
-    # wait for deployment to finish
-    def check_stack():
-        stack = get_stack_details(TEST_STACK_NAME)
-        assert stack['StackStatus'] == 'CREATE_COMPLETE'
+        # deploy template
+        cloudformation.create_stack(StackName=TEST_STACK_NAME, TemplateBody=template)
 
-    retry(check_stack, retries=3, sleep=2)
+        # wait for deployment to finish
+        def check_stack():
+            stack = get_stack_details(TEST_STACK_NAME)
+            assert stack['StackStatus'] == 'CREATE_COMPLETE'
 
-    # assert that bucket has been created
-    assert bucket_exists('cf-test-bucket-1')
-    # assert that queue has been created
-    assert queue_exists('cf-test-queue-1')
-    # assert that stream has been created
-    assert stream_exists('cf-test-stream-1')
+        retry(check_stack, retries=3, sleep=2)
 
+        # assert that bucket has been created
+        assert bucket_exists('cf-test-bucket-1')
+        # assert that queue has been created
+        assert queue_exists('cf-test-queue-1')
+        # assert that stream has been created
+        assert stream_exists('cf-test-stream-1')
 
-def test_validate_template():
-    cloudformation = aws_stack.connect_to_service('cloudformation')
-    template = template_deployer.template_to_json(load_file(TEST_TEMPLATE_1))
-    response = cloudformation.validate_template(TemplateBody=template)
-    assert response['ResponseMetadata']['HTTPStatusCode'] == 200
+    def test_validate_template(self):
+        cloudformation = aws_stack.connect_to_service('cloudformation')
+        template = template_deployer.template_to_json(load_file(TEST_TEMPLATE_1))
+        response = cloudformation.validate_template(TemplateBody=template)
+        assert response['ResponseMetadata']['HTTPStatusCode'] == 200
 
+    def test_validate_invalid_json_template_should_fail(self):
+        cloudformation = aws_stack.connect_to_service('cloudformation')
+        invalid_json = '{"this is invalid JSON"="bobbins"}'
 
-def test_validate_invalid_json_template_should_fail():
-    cloudformation = aws_stack.connect_to_service('cloudformation')
-    invalid_json = '{"this is invalid JSON"="bobbins"}'
-
-    try:
-        response = cloudformation.validate_template(TemplateBody=invalid_json)
-        fail("Should raise ValidationError")
-    except ClientError as err:
-        assert err.response['ResponseMetadata']['HTTPStatusCode'] == 400
-        assert err.response['Error']['Message'] == "Template Validation Error"
+        try:
+            response = cloudformation.validate_template(TemplateBody=invalid_json)
+            self.fail("Should raise ValidationError")
+        except ClientError as err:
+            assert err.response['ResponseMetadata']['HTTPStatusCode'] == 400
+            assert err.response['Error']['Message'] == "Template Validation Error"