Skip to content

feat: Add default Value type for EventBridgeEvent detail #843

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

Merged

Conversation

lmammino
Copy link
Contributor

Issue #, if available: N/D

Description of changes:

When creating a new lambda using cargo lambda new and selecting the event type eventbridge::EventBridgeEvent you end up with broken code:

Screenshot 2024-03-13 at 09 28 57

missing generics for struct aws_lambda_events::eventbridge::EventBridgeEvent
expected 1 generic argument

This makes sense because an EventBridge detail event field is an arbitrary JSON object, so it could vary widely in shape and therefore it is implemented as a generic type that we need to provide ourselves.

So an easy fix would be something like:

// ...
use serde_json::Value;

async fn function_handler(event: LambdaEvent<EventBridgeEvent<Value>>) -> Result<(), Error> {
    // Extract some useful information from the request

    Ok(())
}

except serde_json also needs to be installed with cargo add serde_json, so there's a bit of friction for the user.

CloudWatch events are very similar (unsurprisingly since EventBrigde has spun off CloudWatch events, AFAIK) because they also have a generic detail field which can contain pretty much arbitrary content.

I noticed that the current implementation of the CloudWatchEvent provides a default type and that type is serde_json::Value.

I really like this approach because it provides a smoother starting point for the developer.

So, this PR proposes to adopt the same approach also to the EventBridgeEvent type and default detail to be of type serde_json::Value when no explicit type is provided for the associated generic type.

I hope this makes sense, but IMHO it can make things a little bit more frictionless when wanting to scaffold an eventbridge Lambda.


By submitting this pull request

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I confirm that I've made a best effort attempt to update all relevant documentation.

Copy link
Contributor

@calavera calavera left a comment

Choose a reason for hiding this comment

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

Thanks!

@calavera calavera merged commit aeee3b6 into awslabs:main Mar 13, 2024
5 checks passed
@lmammino lmammino deleted the feat/default-detail-type-for-eventbridge branch March 13, 2024 16:35
@lmammino
Copy link
Contributor Author

Hey @calavera, Is it worth doing a new release for this? Or do you have a specific cadence for that?

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.

2 participants