-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IonLoader is returning 'invalid_state' for the kinesis stream event as QLDB table changes.(Inserting a record) #123
Comments
Here's what I get when I decode the base64 data and interpret it as a UTF-8 string:
This is not Ion text or Ion binary, hence the failures raised by the Ion parser. |
Hi @tgregg The data is received as is from the logs when QLDB stream(changes to QLDB table) raises a Kinesis Event. I have just created a stream in Amazon Console and expect the data to be in Ion format. There is no manipulation of data anywhere. |
Unfortunately, this blob of data is not in the Ion format. I recommend reaching out to the QLDB support team. They'll be better able to answer questions about the data emitted by QLDB. |
@sontalra Were you able to fix this issue? I am working on a similar pipeline and facing the exact same issue. |
Hey @sontalra QLDB delivers stream records to Kinesis as binary-encoded Ion objects and you need to use the Kinesis data stream directly with the
Let me know if this works for you. |
Was there any resolution found for this? We are facing a similar issue, in our case, the stream is parsed directly into Ion values as @juniortads suggested, but our Lambda is showing intermittent behavior. The Ion Loader is able to load sometimes, but fails to load the other time. Our Kinesis Stream is set to only receive from QLDB stream, so it's guaranteed that the data in kinesis stream is a QLDB stream. It seems like QLDB stream is sending non-Ion value data through the Kinesis stream, the doc for QLDB states that the stream is ion binary data, but for some reason, that doesn't seem to be true. |
@ashritbista Below worked for me in Spark: kinesis = ( Below UDF converts Binary ION stream to Json stringdef binary_json_encode(payload): convert_UDF_bin2json = udf(lambda z: binary_json_encode(z), StringType()) json_df = kinesis.withColumn("json_data", convert_UDF_bin2json(kinesis["data"])) |
Hi Team,
I'm writing a lambda for kinesis event processing on the changes to QLDB table.
Similar to https://github.com/aws-samples/amazon-qldb-streams-dmv-sample-lambda-python
I'm using "Amazon.QLDB.Driver" Version="1.0.0-rc.1" which has a dependency on Amazon.IonDotnet 1.0.0.
My Lambda is receiving the kinesis event as:
{ "Records": [ { "kinesis": { "kinesisSchemaVers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EBcWxkYlN0cmVhbUFybnJlY29yZFR5cGVwYXlsb2FkdGFibGVJbmZvdGFibGVOYW1ldGFibGVJZHJldmlzaW9uYmxvY2tBZGRyZXNzc3RyYW5kSWRzZXF1ZW5jZU5vaGFzaGRhdGFWaXJ0dWFsQWNjb3VudElkQW1vdW50VHJhbnNhY3Rpb25EYXRlbWV0YWRhdGFpZHR4VGltZXR4SWQCYXJuOmF3czpxbGRiOmFwLXNvdXRoZWFzdC0yOnh4eHh4eDpzdHJlYW0vcG9jLWxlZGdlci1wb2MtMjQwNS1sZWRnZXIvNTlOYWlYVjF2WE0ya1pPc3VhdUtyeFJFVklTSU9OX0RFVEFJTFMBVmlydHVhbEFjY291bnRUcmFuc2FjdGlvbnMyWmdyM3Y0N1M5R0RzQWQ4c3RETFE5ATl4U3h3OWhNUlhhSWR0ME9ZdFQ0WXgiARgGDHk6dhRXBX9HNwZzCm4zGl9GLmlkNSEKMjAyMC0wNi0wMlQxNjozMDo1NS4wNTRaMGJHSTN2aEZGcGJFWkpYRmlzbHByQyBrDwI2cnE1OWJCTDN2cUZVSFdmMjI0cnI4MhpIFXF+OQ==", "approximateArrivalTimestamp": 1592877325.432 }, "eventSource": "aws:kinesis", "eventVersion": "1.0", "eventID": "shardId-xxxx", "eventName": "aws:kinesis:record", "invokeIdentityArn": "arn:aws:iam::xxx:role/TransactionNotifierLambdaRole", "awsRegion": "ap-southeast-2", "eventSourceARN": "arn:aws:kinesis:ap-southeast-2:xxx:stream/TransactionNotificationStream" } ] }
When I am trying to load the datagram using the IonLoader with decoded Kinesis.Data using base64, I'm getting below error:
Invalid state: IonException at Amazon.IonDotnet.Internals.Text.RawTextReader.ParseNext() at Amazon.IonDotnet.Internals.Text.RawTextReader.HasNext() at Amazon.IonDotnet.Internals.Text.UserTextReader.HasNext() at Amazon.IonDotnet.Internals.Text.RawTextReader.MoveNext() at Amazon.IonDotnet.Internals.PrivateIonWriterBase.WriteValues(IIonReader reader) at Amazon.IonDotnet.Builders.IonLoader.WriteDatagram(IIonReader reader) at Amazon.IonDotnet.Builders.IonLoader.Load(Byte[] data) at Serverless.Handlers.TransactionEventHandler.Add(Stream stream, ILambdaContext contexts) in /home/runner/work/poc-ledger/poc-ledger/Serverless/Handlers/TransactionEventHandler.cs:line 52 at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
The code is as below:
var decodedData = Convert.FromBase64String(record.Kinesis.Data);
var datagram = IonLoader.WithReaderOptions(new ReaderOptions { Format = ReaderFormat.Detect, Encoding = Encoding.ASCII }).Load(decodedData);
And if I dont decode the Kinesis.Data and pass the string directly to loader I'm getting below error:
Numeric value [84] followed by invalid character: 109: FormatException at Amazon.IonDotnet.Internals.Text.TextScanner.FinishLoadNumber(StringBuilder numericText, Int32 c, Int32 token) at Amazon.IonDotnet.Internals.Text.TextScanner.LoadNumber(StringBuilder valueBuffer) at Amazon.IonDotnet.Internals.Text.RawTextReader.LoadTokenContents(Int32 scannerToken) at Amazon.IonDotnet.Internals.Text.RawTextReader.MoveNext() at Amazon.IonDotnet.Internals.PrivateIonWriterBase.WriteValues(IIonReader reader) at Amazon.IonDotnet.Builders.IonLoader.WriteDatagram(IIonReader reader) at Amazon.IonDotnet.Builders.IonLoader.Load(String ionText) at Serverless.Handlers.TransactionEventHandler.Add(Stream stream, ILambdaContext contexts) in /home/runner/work/poc-ledger/poc-ledger/Serverless/Handlers/TransactionEventHandler.cs:line 49 at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
I'm not sure how shall I decode the data from kinesis stream using this sdk. Any help really appreciated.
Note: I have used UTF8 decoding as well.
The text was updated successfully, but these errors were encountered: