Search code examples
amazon-web-servicesaws-lambdaserverlessamazon-kinesis

filter kinesis event by lambda


i have looked at : https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html

to filter events before invoking lambda but i can't achieve that, can you help please?

{'Records': [{'kinesis': {'kinesisSchemaVersion': '1.0', 'partitionKey': '37540688c73d2b2be11490f8b5ae93ff', 'sequenceNumber': '49631675050471285384259191448171119417567571671338975282', 'data': 'H4sIAAAAAAAAADWPwWrDM/dKjZTcuGY41bsqwf5TP7VH0Mr36uLhfYv8PTlNKY8nksaV7DdfShuFB89TcHp9+m/uZC3bJ38GcubFprkQixZRMkbI1SyqI1lgySRK1JKkKtJAmlTSOEJiOwZYfqeWOdFtbFlgxzko2QtPvfzvUFHqfHD/S8r4ANAQAA', 'approximateArrivalTimestamp': 1658758525.02}, 'eventSource': 'aws:kinesis', 'eventVersion': '1.0', 'eventID': 'shardId-000000000003:49631675050471285384259191448171119417567571671338975282', 'eventName': 'aws:kinesis:record', 'invokeIdentityArn': 'arn:aws:iam::XXX:role/XXX', 'awsRegion': 'eu-west-1', 'eventSourceARN': 'arn:aws:kinesis:eu-west-1:XXXX:stream/XXX'}]}

i want to avoid "CONTROL_MESSAGE" so that i tried this pattern on filter : { "data": { "messageType": [ "DATA_MESSAGE" ] } }

but doesn't work ! it is because the data bloc in compressed and encoded ?


Solution

  • It doesn't work because your data property is not a valid JSON.

    Your content seems to be zipped.

    AWS is expecting the content to be a JSON string so they can JSON parse it and apply the filter to the object in memory.