Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Can't deserialize aws_lambda_events::dynamodb::EventRecord due to missing eventVersion field #84

Closed
indiv0 opened this issue Apr 28, 2022 · 1 comment · Fixed by #85
Closed

Comments

@indiv0
Copy link
Contributor

indiv0 commented Apr 28, 2022

Hello! Thank you for this wonderful crate!

I'm using this crate in a Lambda that processes DynamoDB stream events coming from Kinesis.

I can't deserialize the events to aws_lambda_events::dynamodb::EventRecord because the eventVersion field is missing from them. The aws_lambda_events::dynamodb::EventRecord struct has the event_version field as being of type String rather than of type Option<String>. I'm not sure if this is a bug or if I'm just using the wrong type.

I've been able to get around this by duplicating the type, changing the type of the field to Option<String>, and deriving serde::Deserialize on it.

Here is the base64 decoding of the problematic EventRecord. Note the lack of eventVersion field.

{
  "awsRegion":"eu-west-1",
  "eventID":"00000000-0000-0000-0000-000000000000",
  "eventName":"INSERT",
  "userIdentity":null,
  "recordFormat":"application/json",
  "tableName":"examples",
  "dynamodb":{
    "ApproximateCreationDateTime":1649809356015,
    "Keys":{
      "id":{
        "S":"00000000-0000-0000-0000-000000000000"
      }
    },
    "NewImage":{
      "id":{
        "S":"00000000-0000-0000-0000-000000000000"
      },
      "created":{
        "S":"2022-02-16T15:12:00.14Z"
      }
    },
    "SizeBytes":292
  },
  "eventSource":"aws:dynamodb"
}

Here is what the above looks like as the data field of a lambda_runtime::LambdaEvent<aws_lambda_events::event::kinesis::KinesisEvent>.

{
  "Records":[
    {
      "kinesis":{
        "kinesisSchemaVersion":"1.0",
        "partitionKey":"00000000000000000000000000000000",
        "sequenceNumber":"49627941615570055579864951581810255285859251490098511874",
        "data":"eyJhd3NSZWdpb24iOiJldS13ZXN0LTEiLCJldmVudElEIjoiMDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwIiwiZXZlbnROYW1lIjoiSU5TRVJUIiwidXNlcklkZW50aXR5IjpudWxsLCJyZWNvcmRGb3JtYXQiOiJhcHBsaWNhdGlvbi9qc29uIiwidGFibGVOYW1lIjoiZXhhbXBsZXMiLCJkeW5hbW9kYiI6eyJBcHByb3hpbWF0ZUNyZWF0aW9uRGF0ZVRpbWUiOjE2NDk4MDkzNTYwMTUsIktleXMiOnsiaWQiOnsiUyI6IjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCJ9fSwiTmV3SW1hZ2UiOnsiaWQiOnsiUyI6IjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCJ9LCJjcmVhdGVkIjp7IlMiOiIyMDIyLTAyLTE2VDE1OjEyOjAwLjE0WiJ9fSwiU2l6ZUJ5dGVzIjoyOTJ9LCJldmVudFNvdXJjZSI6ImF3czpkeW5hbW9kYiJ9",
        "approximateArrivalTimestamp":1648225669.343
      },
      "eventSource":"aws:kinesis",
      "eventVersion":"1.0",
      "eventID":"shardId-000000000000:49627941615570055579864951581810255285859251490098511874",
      "eventName":"aws:kinesis:record",
      "invokeIdentityArn":"arn:aws:iam::111111111111:role/service-role/body-role-00000000",
      "awsRegion":"eu-west-1",
      "eventSourceARN":"arn:aws:kinesis:eu-west-1:000000000000:stream/examples_changes"
    }
  ]
}
@calavera
Copy link
Owner

Can you open a PR updating the type for that field? there are some fields that are not very well documented, so it's hard at times to know which ones are optional and which ones are not.

calavera pushed a commit that referenced this issue Apr 29, 2022
…N` optional (#85)

* fix(dynamodb): Make `eventSource`, `eventVersion`, and `eventSourceARN` optional

* fix(dynamodb): Add missing `tableName` and `recordFormat` fields

Closes #84.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants