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

feat: Easy Event Deserialization #757

Merged
merged 16 commits into from
Mar 1, 2022

Conversation

jeromevdl
Copy link
Contributor

@jeromevdl jeromevdl commented Feb 17, 2022

Issue #, if available:

Description of changes:

New feature in the serialization module: ability to easily extract the content from an Event (many built-in events).

Ex with API Gateway:

import static software.amazon.lambda.powertools.utilities.EventDeserializer.from;

public class AppParams implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
    public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
        // will automatically extract the content from the body and serialize it as an Order
        Order order = extractDataFrom(event).as(Order.class); 

        // ...
    }
}

Ex with SQS:

import static software.amazon.lambda.powertools.utilities.EventDeserializer.from;

public class AppParams implements RequestHandler<SQSEvent, String> {
    public String handleRequest(SQSEvent event, Context context) {
        // will automatically extract the content from records body, serialize them as Order, and return a list
        List<Order> orders = extractDataFrom(event).asListOf(Order.class); 

        // ...
    }
}

Checklist

Breaking change checklist

RFC issue #:

  • Migration process documented
  • Implement warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pankajagrawal16 pankajagrawal16 changed the title Feature: Easy Event Deserialization feat: Easy Event Deserialization Feb 17, 2022
Copy link
Contributor

@pankajagrawal16 pankajagrawal16 left a comment

Choose a reason for hiding this comment

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

Some suggestions.

} else if (obj instanceof KinesisAnalyticsStreamsInputPreprocessingEvent) {
KinesisAnalyticsStreamsInputPreprocessingEvent event = (KinesisAnalyticsStreamsInputPreprocessingEvent) obj;
return new EventPart(event.getRecords().stream().map(r -> decode(r.getData())).collect(Collectors.toList()));
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

What mechanisms can be have to update these when java lib introduces new event type?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am thinking may be we can have a github action which somehow polls java lib weekly or daily or whatever and create an issue if for powertools if something new is added for events ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not all events make sense in here. I didn't add all, only those where there is a message or something meaningful to extract. Maybe I forgot some interesting ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can get an email on each release of the library. Dependabot will also raise a PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, may be i am overthinking this, we wait for doing anything more until we see it being a problem

@msailes
Copy link
Contributor

msailes commented Feb 18, 2022

Would anything change post v4 of the events library?

It might be worth a quick chat with @andclt.

@@ -45,6 +45,14 @@
<groupId>io.burt</groupId>
<artifactId>jmespath-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

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

In v4 of the events lib, there will be a dependency on Jackson, I don't think that changes anything, just worth noting.

jeromevdl and others added 7 commits February 18, 2022 12:07
…powertools/utilities/EventDeserializerTest.java

Co-authored-by: Pankaj Agrawal <pnkaj.agrwal@gmail.com>
…s#756)

Bumps [maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.2.0 to 3.2.2.
- [Release notes](https://github.com/apache/maven-jar-plugin/releases)
- [Commits](apache/maven-jar-plugin@maven-jar-plugin-3.2.0...maven-jar-plugin-3.2.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-jar-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…rtools#755)

Bumps `aws.sdk.version` from 2.17.130 to 2.17.131.

Updates `software.amazon.awssdk:bom` from 2.17.130 to 2.17.131
- [Release notes](https://github.com/aws/aws-sdk-java-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-java-v2/blob/master/CHANGELOG.md)
- [Commits](aws/aws-sdk-java-v2@2.17.130...2.17.131)

Updates `http-client-spi` from 2.17.130 to 2.17.131
- [Release notes](https://github.com/aws/aws-sdk-java-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-java-v2/blob/master/CHANGELOG.md)
- [Commits](aws/aws-sdk-java-v2@2.17.130...2.17.131)

Updates `url-connection-client` from 2.17.130 to 2.17.131

---
updated-dependencies:
- dependency-name: software.amazon.awssdk:bom
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: software.amazon.awssdk:http-client-spi
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: software.amazon.awssdk:url-connection-client
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
remove trailing slash for multiple params
- javadoc
- indentation
- better edge cases handling
Copy link
Contributor

@pankajagrawal16 pankajagrawal16 left a comment

Choose a reason for hiding this comment

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

Minor suggestion, from code perspective, it looks good to me, so if you want to start documenting it.

@jeromevdl
Copy link
Contributor Author

@pankajagrawal16 @msailes ready for further review / merge

msailes
msailes previously approved these changes Mar 1, 2022
Copy link
Contributor

@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.

👍🏻

Copy link
Contributor

@pankajagrawal16 pankajagrawal16 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. Just one minor suggestion on docs.

docs/utilities/serialization.md Show resolved Hide resolved
Copy link
Contributor

@pankajagrawal16 pankajagrawal16 left a comment

Choose a reason for hiding this comment

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

Great 🎉 ... cc @kozub

@pankajagrawal16 pankajagrawal16 merged commit bcf9aba into aws-powertools:master Mar 1, 2022
@jeromevdl jeromevdl mentioned this pull request Mar 1, 2022
1 task
@jeromevdl jeromevdl deleted the json-utility branch November 4, 2022 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants