Java-无法将DynamoDb Stream事件映射到StreamRecord(空)

时间:2019-11-15 14:30:02

标签: java amazon-web-services amazon-dynamodb aws-sdk

我正在使用:https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/dynamodb/model/StreamRecord.html

我有来自dynamodb流的以下事件:

{
  "Records": [
    {
      "eventID": "whatever",
      "eventName": "INSERT",
      "eventVersion": "1.1",
      "eventSource": "aws:dynamodb",
      "awsRegion": "eu-west-1",
      "dynamodb": {
        "ApproximateCreationDateTime": 12345678,
        "Keys": {
          "id": {
            "S": "some-id"
          },
          "parentId": {
            "S": "some-parent-id"
          }
        },
        "SequenceNumber": "something",
        "SizeBytes": 820,
        "StreamViewType": "KEYS_ONLY"
      },
      "eventSourceARN": "some-arn"
    }
  ]
}

这以InputStream的形式出现在我的lambda函数中,因此我将其转换为JSON并尝试将其映射到StreamRecord

  public static StreamRecord getStreamEventAsStreamRecord(final JsonNode input)
      throws JsonProcessingException {
    final ObjectMapper objectMapper = new ObjectMapper();

    objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    final StreamRecord record =
        objectMapper.treeToValue(input, StreamRecord.serializableBuilderClass()).build();

    return record;
  }

我用它:

JsonNode event = objectMapper.readTree(input); // The input as outlines above coming from DDB streams

// assume that the Records array has been iterated
for(JsonNode record: records){
  StreamRecord myrecord = getStreamEventAsStreamRecord(record);
}

调用myrecord.keys().keySet()时,即使收到的有效负载中有密钥,我也会得到[]。我对StreamRecord的映射/序列化处理不正确吗?

0 个答案:

没有答案