diff --git a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java index d9547a76..4f93ca20 100644 --- a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java +++ b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java @@ -16,7 +16,9 @@ public static Record toRecordV2(final DynamodbEvent.DynamodbStreamRecord record) .eventSource(record.getEventSource()) .eventVersion(record.getEventVersion()) .userIdentity( - DynamodbIdentityTransformer.toIdentityV2(record.getUserIdentity()) + record.getUserIdentity() != null + ? DynamodbIdentityTransformer.toIdentityV2(record.getUserIdentity()) + : null ) .build(); } diff --git a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java index 69645844..3218a856 100644 --- a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java +++ b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java @@ -50,4 +50,14 @@ public void testToRecordV2() { Assertions.assertEquals(record_v2, convertedRecord); } + @Test + public void testToRecordV2WhenUserIdentityIsNull() { + DynamodbEvent.DynamodbStreamRecord record = record_event.clone(); + record.setUserIdentity(null); + + Assertions.assertDoesNotThrow(() -> { + DynamodbRecordTransformer.toRecordV2(record); + }); + } + } \ No newline at end of file