'Validation error ...........: Value '<TestStream>' at 'streamName' failed to satisfy constraint

Getting error when I am trying to migrate stream data from MYSQL to Kinesis. Help me to fix this.

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutRecord operation: 1 validation error detected: Value '' at 'streamName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+

import json
import boto3
import pymysql
import socket,array
import pandas as pd
from datetime import datetime
from pymysqlreplication import BinLogStreamReader
from pymysqlreplication.row_event import (
    DeleteRowsEvent,
    UpdateRowsEvent,
    WriteRowsEvent,
)
class DateTimeEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, datetime):
            return o.isoformat()

        return json.JSONEncoder.default(self, o)

connection = {
    "host": "127.0.0.1",
    "port": 3306,
    "user": "root",
    "passwd": "root"}

def main():
  kinesis = boto3.client("kinesis",region_name='ap-south-1')
  stream = BinLogStreamReader(
            connection_settings=connection,
            only_events=[DeleteRowsEvent, WriteRowsEvent, UpdateRowsEvent],
            server_id=100,
            blocking=True,
            log_file='mysql-bin.000003',
            resume_stream=True,
        )
  for binlogevent in stream:
    for row in binlogevent.rows:
      event = {"schema": binlogevent.schema,
      "table": binlogevent.table,
      "type": type(binlogevent).__name__,
      "row": row
      }       
      kinesis.put_record(StreamName="<MysqlKinesisStream>", Data=json.dumps(event,cls=DateTimeEncoder), 
PartitionKey="default",)
      print (json.dumps(event))
if __name__ == "__main__":
   main()


Solution 1:[1]

This means that the name "<TestStream>" is an invalid Kinesis stream name. Use the Kinesis stream name you created in AWS.

Kinesis names must match the regex pattern [a-zA-Z0-9_.-]+

Solution 2:[2]

Could it be that there may have been an issue with an extra blank or space that was in front of the stream name when you added it as a environment variable value in the Configuration tab for your lambda? That is what happened to me. Somehow there was a preceding blank before my stream name when I entered it as a value under the Configuration KEY VALUE pairs and I kept getting that error and I was wondering to myself if it could really have an extraneous character at the beginning of the stream name string.

As soon as I made that update to remove that preceding space from the stream name string, everything worked which is exactly what the grep string in the error exception message was indicating (no blanks nor #,$@ or any other strange character should be in the stream name string):

{ "URL": "https://7rai4b8gwk.execute-api.us-west-2.amazonaws.com/dev/events?test=1", "error": "", "response_body": { "message": "success" }, "response_status_code": 200 }

Before that, I got the exception but also got"

{ "URL": "https://7rai4b8gwk.execute-api.us-west-2.amazonaws.com/dev/events?test=1", "error": "", "response_body": { "message": "process failed 2" }, "response_status_code": 200 }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris Williams
Solution 2 Anthony Williams