Skip to content
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

S3EventNotification cannot take an unversioned S3EventNotification fromJson() -> toJson() -> fromJson() #5730

Open
1 task
zakeckert opened this issue Nov 26, 2024 · 1 comment
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@zakeckert
Copy link

Describe the bug

Short version:
An unversioned S3 object create message is sent to SQS. SQS message body is read into object using var event = software.amazon.awssdk.eventnotifications.s3.model.S3EventNotification.fromJson(). event is written back into a string using event.toJson() and put into an SQS message and put on the queue. When reading the new SQS message body using S3EventNotification.fromJson(), it fails with java.lang.IllegalArgumentException: 'versionId' was not a string

Long version:
I have an S3 bucket that sends notifications to an SQS queue on object create. The S3 object has no version. Because the S3 object has no version, there is no value for Records[0].S3.S3Object.versionId. It is not present in the JSON body.

I get the SQS message and read its body (a string) into an S3EventNotification using software.amazon.awssdk.eventnotifications.s3.model.S3EventNotification.fromJson(message.getBody()).

eventNotification.getRecords().get(0).getS3().getObject().getVersionId() correctly returns null, because there was no value in the JSON body.

I attempt to process the S3 object. If I am unable to do so, I create a new message and put it back on the SQS queue. I create the SQS message body by doing eventNotification.toJson(). This string this creates includes "versionId":null in Records[0].S3.S3Object.versionId.

When I get the re-queued message from SQS, I am unable to parse it with software.amazon.awssdk.eventnotifications.s3.model.S3EventNotification.fromJson(message.getBody()), failing with java.lang.IllegalArgumentException: 'versionId' was not a string

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I would expect to be able to:

  1. read a valid S3 Event Notification JSON string into an object S3EventNotification.fromJson()

  2. write the object back into a string using S3EventNotification.toJson()

  3. read that string again using S3EventNotification.fromJson()

Current Behavior

Currently:

  1. read a valid S3 Event Notification JSON string into an object S3EventNotification.fromJson()

  2. write the object back into a string using S3EventNotification.toJson()

  3. read that string again using S3EventNotification.fromJson() fails because the string has "versionId":null, and versionId must be a string.

Reproduction Steps

public void eventBodyTest() {
    var msgBodyNoVersionId = "{\"Records\":[{\"eventVersion\":\"event version\",\"eventSource\":\"event source\",\"awsRegion\":\"us-east-1\",\"eventTime\":\"2024-11-26T23:12:22Z\",\"eventName\":\"ObjectCreated:Put\",\"userIdentity\":{\"principalId\":\"principalId\"},\"requestParameters\":{\"sourceIPAddress\":\"sourceIpAddress\"},\"responseElements\":{\"x-amz-request-id\":\"xAmzRequestId\",\"x-amz-id-2\":\"xamzid2\"},\"s3\":{\"s3SchemaVersion\":\"s3SchemaVersion\",\"configurationId\":\"configId\",\"bucket\":{\"name\":\"mock-recordings\",\"ownerIdentity\":{\"principalId\":\"principalId\"},\"arn\":\"arn\"},\"object\":{\"key\":\"screenrecordings/f797615450ca4d57955d46d0/ac204e68-517c-4b64-aa58-462d0aece2cb//recoding.webm\",\"size\":0,\"eTag\":\"etag\",\"sequencer\":\"sequencer\"}},\"glacierEventData\":{\"restoreEventData\":{\"lifecycleRestorationExpiryTime\":\"2024-11-26T23:12:22Z\",\"lifecycleRestoreStorageClass\":\"lifecycleStorageClass\"}},\"replicationEventData\":{\"replicationRuleId\":\"replicationRuleId\",\"destinationBucket\":\"destinationBucket\",\"s3Operation\":\"s3Operation\",\"requestTime\":\"requestTime\",\"failureReason\":\"failureReason\",\"threshold\":\"threshold\",\"replicationTime\":\"replicationTime\"},\"intelligentTieringEventData\":{\"destinationAccessTier\":\"destinationAccessTier\"},\"lifecycleEventData\":{\"transitionEventData\":{\"destinationStorageClass\":\"destinationStorageClass\"}}}]}";
    var msg = S3EventNotification.fromJson(msgBodyNoVersionId);
    var msgStr = msg.toJson();
    var msg2 = S3EventNotification.fromJson(msgStr);
    return;
}

Possible Solution

Ignore null values when parsing the JSON string, or remove them before parsing.

Additional Information/Context

No response

AWS Java SDK version used

2.26.20

JDK version used

openjdk 17.0.7 2023-04-18

Operating System and version

macOS Sonoma Version 14.6.1

@zakeckert zakeckert added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 26, 2024
@zakeckert zakeckert changed the title (short issue description) S3EventNotification cannot take an unversioned S3EvetnNotification fromJson() -> toJson() -> fromJson() Nov 26, 2024
@zakeckert zakeckert changed the title S3EventNotification cannot take an unversioned S3EvetnNotification fromJson() -> toJson() -> fromJson() S3EventNotification cannot take an unversioned S3EventNotification fromJson() -> toJson() -> fromJson() Nov 26, 2024
@debora-ito debora-ito self-assigned this Dec 3, 2024
@debora-ito debora-ito added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2024
@debora-ito
Copy link
Member

@zakeckert I can reproduce the error java.lang.IllegalArgumentException: 'versionId' was not a string. Thank you for reporting.

fromJson() ➡️ toJson() ➡️ fromJson() should work seamlessly, we'll work on a fix.

@debora-ito debora-ito removed the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Dec 5, 2024
@debora-ito debora-ito removed their assignment Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants