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

Added event class MskFirehoseEvent.java for Firehose Lambda transformation when MSK is the source #490

Merged
merged 28 commits into from
Jul 10, 2024

Conversation

ShashankAWS
Copy link
Contributor

@ShashankAWS ShashankAWS commented Jul 1, 2024

Issue #, if available:
Not available :

Description of changes:
In case of the data flow like :
MSK -----> Firehose ---> invokes Lambda transformation with event -------> Lambda returns the transformed record back to Firehose ---------> Firehose Deliver's the data to S3 or any other destination.

The issue lies when Firehose tries to invoke the Lambda, with event [1], Lambda java event libraries does not have any event class to support this event.

[1] event :
{
"invocationId": "",
"sourceMSKArn": "",
"deliveryStreamArn": "",
"region": "us-east-1",
"records": [
{
"recordId": "00000000000000000000000000000000000000000000000000000000000000",
"approximateArrivalTimestamp": 1716369573887,
"mskRecordMetadata": {
"offset": "0",
"partitionId": "1",
"approximateArrivalTimestamp": 1716369573887
},
"kafkaRecordValue": ""
}
]
}

To handle these events, adding the class MskFirehoseEvent.

Target (OCI, Managed Runtime, both): both

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@msailes
Copy link
Collaborator

msailes commented Jul 1, 2024

Thanks for the PR. Can you review some of the recent PRs / commits and model your class like those.

Favour Lombok annotations over getters / setters / toString / equals.
Check the copyright notice

Copy link
Contributor

@smirnoal smirnoal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to what Mark's said, please add a test for this event to https://github.com/aws/aws-lambda-java-libs/tree/main/aws-lambda-java-tests

/**
* Created by vermshas on 6/28/24.
* Event format is below:
* {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to the docs here

* Event format is below:
* {
* "invocationId": "",
* "sourceMSKArn": "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to model the sourceMSKArn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added sourceMSKArn.

@Getter
@Setter
@ToString
@EqualsAndHashCode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the following lombok annotations

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change done.

@ShashankAWS
Copy link
Contributor Author

Hi, I have added the test for the event, response class and updated Readme.

Changed naming conventions.

/**
* Created by vermshas on 6/28/24.
* {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this example and link the docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the example, I am not able to find any document stating the specific event.

Changed packaging for event handler.
public Result result;
public ByteBuffer kafkaRecordValue;

public Record(String recordId, Result result, ByteBuffer kafkaRecordValue) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the constructor by using Lombok.

Removed the event structure, we do not have documents stating the event structure for this case.
Expanded the Lombok import, updated java doc for the class and removed the record constructor.
Added new test.
escaped quotes in JSON
Added values to ARN fields.
added MSKMetadata check and Approximate arrivaltimestamp.
@smirnoal
Copy link
Contributor

smirnoal commented Jul 9, 2024

use the following license text in all source files:

/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

import lombok.NoArgsConstructor;

/**
* Created by vermshas on 6/28/24.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it needed?

Copy link
Contributor Author

@ShashankAWS ShashankAWS Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed saw it added to some classes and thought its required. Added copyright/license text to MSKFirehoseEvent.java and MSKFirehoseResponse.java. Do we need to add license text to sample as well ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, to all source code, please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added license text to samples as well.

added copyright text.
Added Copyright text.
Copy link
Collaborator

@msailes msailes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@smirnoal smirnoal merged commit c0b4f60 into aws:main Jul 10, 2024
2 checks passed
msailes pushed a commit to msailes/aws-lambda-java-libs that referenced this pull request Jul 11, 2024
…ation when MSK is the source (aws#490)

* Create MskFirehoseEvent.java
* Create MSKFirehoseResponse.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants