2 回答
- 最新
- 投票最多
- 评论最多
0
Hi whighsmith,
looks like it's a json event.
See here:
https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html
{
"eventSourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:canaryclusterb2a659a2-qo5tcmqkcl03",
"events": [
{
"event": {
"_id": {
"_data": "0163eeb6e7000000090100000009000041e1"
},
"clusterTime": {
"$timestamp": {
"t": 1676588775,
"i": 9
}
},
"documentKey": {
"_id": {
"$oid": "63eeb6e7d418cd98afb1c1d7"
}
},
"fullDocument": {
"_id": {
"$oid": "63eeb6e7d418cd98afb1c1d7"
},
"anyField": "sampleValue"
},
"ns": {
"db": "test_database",
"coll": "test_collection"
},
"operationType": "insert"
}
}
],
"eventSource": "aws:docdb"
}
Sincerely Heiko
已回答 5 个月前
0
I went with this solution. I generated classes from the incoming JSON data, then had to update generated types to use BsonTimestamp for $timestamp and BsonBinaryData for $binary data.
public Task DocumentDbEventConsumer(object events, ILambdaContext context)
{
var jsonString = events.ToString(); //Get JSON data
var bsonDocument = BsonSerializer.Deserialize<BsonDocument>(jsonString); //Deserialize to BsonDocument
var docDbEvents = BsonSerializer.Deserialize<DocumentDbEvents>(bsonDocument); //Deserialize bsonDocument to the class generated from JSON data.
There is likely already a type that can be used instead of "object", but I don't know what it is. If you know, then please post your answer here. Thanks.
已回答 5 个月前
相关内容
- AWS 官方已更新 4 年前
- AWS 官方已更新 8 个月前
- AWS 官方已更新 3 年前
Thank you for your answer; however, there should already be a model type defined to consume this JSON data. Is there not? The internal event data looks like "ChangeStreamDocument<BsonDocument>" which comes from the model defined in MongoDB.Driver. Do I have to generate my own model class from the JSON structure or is there a type pre-defined?
Generally, the class looks like the following: Note the use of "ChangeStreamDocument<BsonDocument>"
Thanks.