Summary
We are excited to announce a new integration for Event Handler to work with AWS AppSync Events APIs. This utility provides a structured way to handle AppSync real-time events through dedicated handler methods, automatic routing, and flexible configuration options.
New Event Handler for AppSync Events
The new AppSyncEventsResolver
is designed to streamline working with AWS AppSync real-time APIs by:
- Handling publish and subscribe events with dedicated handler methods
- Routing events automatically based on namespace and channel patterns
- Supporting wildcard patterns for catch-all handlers
- Controlling event aggregation for batch processing
- Implementing graceful error handling
Handling publish events
You can register handlers for publish events using the OnPublish
method and specifying a pattern for the namespace and channels. This is useful when you want to modify payload content, persist the message in a database, or apply business logic and conditionally filter messages out.
Handling subscribe events
You can use the OnSubscribe
method to process subscription requests before allowing clients to connect to specific channels. This enables authorization checks and subscription filtering based on client context or payload attributes, as well as subscription tracking, for example:
Working with aggregated processing
You can use the OnPublishAggregate
method to process multiple events together as a batch. This is useful when you need to optimize database operations, or want to have full control over how the messages are processed.
AppSync Events FAQs
Q: Can I handle different types of events from the same channel?
A: Yes, you can register different handlers for publish and subscribe events on the same channel.
Q: How does handler precedence work with wildcard patterns?
A: More specific patterns take precedence over wildcards. For example, /default/channel1
will be chosen over /default/
, which will be chosen over /
.
Q: What happens when an exception occurs in my handler?
A: With individual processing, the utility catches exceptions and includes them in the response for the specific event while still processing other events. You can also explicitly raise an UnauthorizedException
exception to reject the entire request.
Q: Does the order of async event processing matter?
A: No, AppSync Events doesn't guarantee delivery order. As long as each response includes the original event ID, AppSync processes them correctly regardless of order.
Q: Can I process multiple events as a batch?
A: Yes, use OnPublishAggregate
to receive all matching events as a batch. When doing so, you're responsible implementing the logic to process them and return a list of corresponding items.
Changes
📜 Documentation updates
- chore: Feature/appsync events (#858) by @hjgraca
- chore(deps): bump squidfunk/mkdocs-material from
047452c
to23b6978
in /docs (#830) by @dependabot[bot]
🔧 Maintenance
- chore: Feature/appsync events (#858) by @hjgraca
- chore(deps): bump aws-cdk-lib from 2.186.0 to 2.189.0 (#848) by @dependabot[bot]
- chore(deps): bump actions/setup-node from 4.3.0 to 4.4.0 (#851) by @dependabot[bot]
- chore: update changelog with latest changes (#849) by @hjgraca
- chore(ci): update build_changelog.yml (#847) by @hjgraca
- chore(deps): bump squidfunk/mkdocs-material from
047452c
to23b6978
in /docs (#830) by @dependabot[bot] - chore(deps): bump zgosalvez/github-actions-ensure-sha-pinned-actions from 3.0.22 to 3.0.23 (#838) by @dependabot[bot]
- chore(deps): bump actions/setup-python from 5.4.0 to 5.5.0 (#837) by @dependabot[bot]
- chore(deps): bump github/codeql-action from 3.28.10 to 3.28.15 (#836) by @dependabot[bot]
- chore(deps): bump aws-cdk-lib from 2.180.0 to 2.186.0 (#829) by @dependabot[bot]
- chore(deps): bump actions/download-artifact from 4.1.9 to 4.2.1 (#825) by @dependabot[bot]
- chore(deps): bump actions/upload-artifact from 4.6.1 to 4.6.2 (#823) by @dependabot[bot]
This release was made possible by the following contributors:
@dependabot[bot], @hjgraca, Release bot and dependabot[bot]