# Buggy code
def post_request():
    action = request.headers.get("x-amz-target")
    data = json.loads(to_str(request.data))
    response = None
    if action == "%s.ListDeliveryStreams" % ACTION_HEADER_PREFIX:
        response = {
            "DeliveryStreamNames": get_delivery_stream_names(),
            "HasMoreDeliveryStreams": False,
        }
    elif action == "%s.CreateDeliveryStream" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        region_name = extract_region_from_auth_header(request.headers)
        response = create_stream(
            stream_name,
            delivery_stream_type=data.get("DeliveryStreamType"),
            delivery_stream_type_configuration=data.get(
                "KinesisStreamSourceConfiguration"
            ),
            s3_destination=data.get("S3DestinationConfiguration"),
            elasticsearch_destination=data.get("ElasticsearchDestinationConfiguration"),
            tags=data.get("Tags"),
            region_name=region_name,
        )
    elif action == "%s.DeleteDeliveryStream" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        response = delete_stream(stream_name)
    elif action == "%s.DescribeDeliveryStream" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        response = get_stream(stream_name)
        if not response:
            return error_not_found(stream_name)
        response = {"DeliveryStreamDescription": response}
    elif action == "%s.PutRecord" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        record = data["Record"]
        put_record(stream_name, record)
        response = {"RecordId": str(uuid.uuid4())}
    elif action == "%s.PutRecordBatch" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        records = data["Records"]
        put_records(stream_name, records)
        request_responses = []
        for i in records:
            request_responses.append({"RecordId": str(uuid.uuid4())})
        response = {"FailedPutCount": 0, "RequestResponses": request_responses}
    elif action == "%s.UpdateDestination" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        version_id = data["CurrentDeliveryStreamVersionId"]
        destination_id = data["DestinationId"]
        s3_update = (
            data["S3DestinationUpdate"] if "S3DestinationUpdate" in data else None
        )
        update_destination(
            stream_name=stream_name,
            destination_id=destination_id,
            s3_update=s3_update,
            version_id=version_id,
        )
        es_update = (
            data["ESDestinationUpdate"] if "ESDestinationUpdate" in data else None
        )
        update_destination(
            stream_name=stream_name,
            destination_id=destination_id,
            es_update=es_update,
            version_id=version_id,
        )
        response = {}
    elif action == "%s.ListTagsForDeliveryStream" % ACTION_HEADER_PREFIX:
        response = get_delivery_stream_tags(
            data["DeliveryStreamName"],
            data.get("ExclusiveStartTagKey"),
            data.get("Limit", 50),
        )
    else:
        response = error_response(
            'Unknown action "%s"' % action, code=400, error_type="InvalidAction"
        )

    if isinstance(response, dict):
        response = jsonify(response)
    return response


# Traceback (TypeError)
2020-02-05T17:05:30:ERROR:flask.app: Exception on / [POST]
Traceback (most recent call last):
File "/opt/code/localstack/.venv/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/opt/code/localstack/.venv/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/code/localstack/.venv/lib/python3.7/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.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/opt/code/localstack/.venv/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/opt/code/localstack/.venv/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/code/localstack/.venv/lib/python3.7/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/firehose/firehose_api.py", line 276, in post_request
es_update=es_update, version_id=version_id)
TypeError: update_destination() got an unexpected keyword argument 'es_update'

# Fixed code
def post_request():
    action = request.headers.get("x-amz-target")
    data = json.loads(to_str(request.data))
    response = None
    if action == "%s.ListDeliveryStreams" % ACTION_HEADER_PREFIX:
        response = {
            "DeliveryStreamNames": get_delivery_stream_names(),
            "HasMoreDeliveryStreams": False,
        }
    elif action == "%s.CreateDeliveryStream" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        region_name = extract_region_from_auth_header(request.headers)
        response = create_stream(
            stream_name,
            delivery_stream_type=data.get("DeliveryStreamType"),
            delivery_stream_type_configuration=data.get(
                "KinesisStreamSourceConfiguration"
            ),
            s3_destination=data.get("S3DestinationConfiguration"),
            elasticsearch_destination=data.get("ElasticsearchDestinationConfiguration"),
            tags=data.get("Tags"),
            region_name=region_name,
        )
    elif action == "%s.DeleteDeliveryStream" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        response = delete_stream(stream_name)
    elif action == "%s.DescribeDeliveryStream" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        response = get_stream(stream_name)
        if not response:
            return error_not_found(stream_name)
        response = {"DeliveryStreamDescription": response}
    elif action == "%s.PutRecord" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        record = data["Record"]
        put_record(stream_name, record)
        response = {"RecordId": str(uuid.uuid4())}
    elif action == "%s.PutRecordBatch" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        records = data["Records"]
        put_records(stream_name, records)
        request_responses = []
        for i in records:
            request_responses.append({"RecordId": str(uuid.uuid4())})
        response = {"FailedPutCount": 0, "RequestResponses": request_responses}
    elif action == "%s.UpdateDestination" % ACTION_HEADER_PREFIX:
        stream_name = data["DeliveryStreamName"]
        version_id = data["CurrentDeliveryStreamVersionId"]
        destination_id = data["DestinationId"]
        s3_update = (
            data["S3DestinationUpdate"] if "S3DestinationUpdate" in data else None
        )
        update_destination(
            stream_name=stream_name,
            destination_id=destination_id,
            s3_update=s3_update,
            version_id=version_id,
        )
        es_update = (
            data["ESDestinationUpdate"] if "ESDestinationUpdate" in data else None
        )
        update_destination(
            stream_name=stream_name,
            destination_id=destination_id,
            elasticsearch_update=es_update,
            version_id=version_id,
        )
        response = {}
    elif action == "%s.ListTagsForDeliveryStream" % ACTION_HEADER_PREFIX:
        response = get_delivery_stream_tags(
            data["DeliveryStreamName"],
            data.get("ExclusiveStartTagKey"),
            data.get("Limit", 50),
        )
    else:
        response = error_response(
            'Unknown action "%s"' % action, code=400, error_type="InvalidAction"
        )

    if isinstance(response, dict):
        response = jsonify(response)
    return response