Repository: localstack/localstack

Issue:
describe-stream crashes in docker-image
steps to reproduce:
create table:
```
aws dynamodb create-table --table-name MusicCollection --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --endpoint http://localhost:4569
```
Enable stream:
```
aws dynamodb update-table --table-name MusicCollection --stream-specification StreamEnabled=true,StreamViewType=NEW_IMAGE --endpoint http://localhost:4569
```
describe-stream using the stream arn from previous step:
```
aws dynamodbstreams describe-stream --stream-arn arn:aws:dynamodb:eu-central-1:000000000000:table/MusicCollection/stream/2019-09-29T12:25:50.316 --endpoint http://localhost:4570
```
crash:
```
Traceback (most recent call last):
  File "/opt/code/localstack/.venv/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/code/localstack/.venv/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/code/localstack/.venv/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/code/localstack/.venv/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/code/localstack/.venv/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/opt/code/localstack/.venv/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/code/localstack/.venv/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/code/localstack/localstack/services/dynamodbstreams/dynamodbstreams_api.py", line 89, in post_request
    shard['ShardId'] = shard_id(stream_name, shard['ShardId'])
  File "/opt/code/localstack/localstack/services/dynamodbstreams/dynamodbstreams_api.py", line 148, in shard_id
    return '-'.join([kinesis_shard_id, random_id(stream_arn, kinesis_shard_id)])
  File "/opt/code/localstack/localstack/services/dynamodbstreams/dynamodbstreams_api.py", line 144, in random_id
    return uuid.uuid5(namespace, to_bytes(kinesis_shard_id)).hex
  File "/usr/lib/python3.6/uuid.py", line 628, in uuid5
    hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest()
TypeError: encoding without a string argument
```


Discussion:

Resolving patch:
diff --git a/localstack/services/dynamodbstreams/dynamodbstreams_api.py b/localstack/services/dynamodbstreams/dynamodbstreams_api.py
--- a/localstack/services/dynamodbstreams/dynamodbstreams_api.py
+++ b/localstack/services/dynamodbstreams/dynamodbstreams_api.py
@@ -1,6 +1,7 @@
 import json
 import uuid
 import hashlib
+import six
 from flask import Flask, jsonify, request, make_response
 from localstack.services import generic_proxy
 from localstack.utils.aws import aws_stack
@@ -140,7 +141,9 @@ def stream_name_from_stream_arn(stream_arn):
 
 def random_id(stream_arn, kinesis_shard_id):
     namespace = uuid.UUID(bytes=hashlib.sha1(to_bytes(stream_arn)).digest()[:16])
-    return uuid.uuid5(namespace, to_bytes(kinesis_shard_id)).hex
+    if six.PY2:
+        kinesis_shard_id = to_bytes(kinesis_shard_id, 'utf-8')
+    return uuid.uuid5(namespace, kinesis_shard_id).hex
 
 
 def shard_id(stream_arn, kinesis_shard_id):


Test patch: