20

I'm trying to stream rds through kinesis data stream but it is giving me this error:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutRecord operation: 1 validation error detected: Value 'arn:aws:kinesis:us-west-2:xxxxxxxxxx:stream/rds-temp-leads-stream' at 'streamName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+

What can I do to fix this?


import json
import boto3
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)

def main():
  mysql = {
      "host": "",
      "port":,
      "user": "",
      "passwd": "",
      "db": ""}
  kinesis = boto3.client("kinesis", region_name = 'us-west-2')

  stream = BinLogStreamReader(
    connection_settings = mysql,
    server_id=100,
    blocking = True,
    log_file='mysql-bin.000003',
    resume_stream=True,
    only_events=[DeleteRowsEvent, WriteRowsEvent, UpdateRowsEvent]) 
  for binlogevent in stream:
    for row in binlogevent.rows:
      print row
      event = {"schema": binlogevent.schema,
      "table": binlogevent.table,
      "type": type(binlogevent).__name__,
      "row": row
      }

      kinesis.put_record(StreamName="jhgjh", Data=json.dumps(event, cls=DateTimeEncoder), PartitionKey="default")
      #print json.dumps(event)

if __name__ == "__main__":
   main()

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Ekta Varshney
  • 431
  • 1
  • 3
  • 13

3 Answers3

17

remove 'arn:aws:kinesis:us-west-2:xxxxxxxxxx:stream/rds-temp-leads-stream' this from stream name. Just put the name of stream there like "rds-temp-leads-stream"

Ekta Varshney
  • 431
  • 1
  • 3
  • 13
  • Hi @Ekta, do you know if KCL library also supports reading from DynamoDB Streams? If yes, the dynamoDB streams only have an ARN but no name. In that case, how to configure the Kinesis Consumer settings? – Jeet Banerjee Jun 01 '22 at 08:07
  • Very weird. I did not deliberately add anything just did: ```sam init sam build sam deploy --guided``` Then experience this error. And it happens to me all the sam template – Xin Jan 17 '23 at 04:56
1

Based on the error:

1 validation error detected: Value 'arn:aws:kinesis:us-west-2:xxxxxxxxxx:stream/rds-temp-leads-stream' at 'streamName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+

The highlighted value : arn:aws:kinesis:us-west-2:xxxxxxxxxx:stream/rds-temp-leads-stream doesn't match the regular expression [a-zA-Z0-9_.-]+ which causes the validation error.

This is because you do not need to add the full ARN and just add the name of your stream. i.e rds-temp-leads-stream

I'm not seeing it on the code but likely this line got the error:

kinesis.put_record(StreamName="jhgjh", Data=json.dumps(event, cls=DateTimeEncoder), PartitionKey="default")

Where "StreamName" should follow the same pattern as above. Reference can be found below: https://docs.aws.amazon.com/kinesis/latest/APIReference/API_PutRecord.html

Sir Markpo
  • 456
  • 4
  • 6
0

For my case, I also had to remove sub folder in the address like this:

Incorrect

bucket='s3://image-video/image/'
photo='scene_academy.jpg'

client=boto3.client('rekognition')
response = client.detect_labels(Image={'S3Object':{'Bucket':bucket,'Name':photo}},
        MaxLabels=10)

Correct

bucket='image-video'
photo='image/scene_academy.jpg'

client=boto3.client('rekognition')
response = client.detect_labels(Image={'S3Object':{'Bucket':bucket,'Name':photo}},
        MaxLabels=10)

Runtime Environment: AWS S3 Bucket

Cloud Cho
  • 1,594
  • 19
  • 22