Docs Home → Atlas App Services
Send Trigger Events to AWS EventBridge
On this page
Overview
MongoDB offers an AWS Eventbridge partner event source that lets you send Atlas Trigger events to an event bus instead of calling an Atlas Function. You can configure any Trigger type to send events to EventBridge. Database Triggers also support custom error handling, to reduce trigger suspensions due to non-critical errors.
All you need to send Trigger events to EventBridge is an AWS account ID. This guide walks through finding your account ID, configuring the Trigger, associating the Trigger event source with an event bus, and setting up custom error handling.
Note
Official AWS Partner Event Source Guide
This guide is based on Amazon's Receiving Events from a SaaS Partner documentation.
Procedure
Note
The AWS put entry for an EventBridge trigger event must be smaller than 256 KB.
Learn how to reduce the size of your PutEvents entry in the Performance Optimization section.
Set Up the MongoDB Partner Event Source
To send trigger events to AWS EventBridge, you need the AWS account ID of the account that should receive the events. Open the Amazon EventBridge console and click Partner event sources in the navigation menu. Search for the MongoDB partner event source and then click Set up.
On the MongoDB partner event source page, click Copy to copy your AWS account ID to the clipboard.
Configure the Trigger
Once you have the AWS account ID, you can configure a trigger to send events to EventBridge.
Note
Supported AWS Regions
For a full list of supported AWS regions, refer to Amazon's Receiving Events from a SaaS Partner guide.
Associate the Trigger Event Source with an Event Bus
Go back to the EventBridge console and choose Partner event sources in the navigation pane. In the Partner event sources table, find and select the Pending trigger source and then click Associate with event bus.
On the Associate with event bus screen, define any required access permissions for other accounts and organizations and then click Associate.
Once confirmed, the status of the trigger event source changes from Pending to Active, and the name of the event bus updates to match the event source name. You can now start creating rules that trigger on events from that partner event source. For more information, see Creating a Rule That Triggers on a SaaS Partner Event.
Custom Error Handling
Note
Only Database Triggers Support Custom Error Handlers
Currently, only database triggers support custom error handling. Authentication triggers and scheduled triggers do not support custom error handling at this time.
You can create an error handler to be executed on a trigger failure, when retry does not succeed. Custom error handling allows you to determine whether an error from AWS EventBridge is critical enough to suspend the Trigger, or if it is acceptable to ignore the error and continue processing other events. For more information on suspended database triggers, refer to Suspended Triggers.
Create a New Custom Error Handler
Error Handler Parameters
The default error handler has two parameters: error
and changeEvent
.
error
Has the following two attributes:
code
: The code for the errored EventBridge put request. For a list of error codes used by the error handler, see the below section.message
: The unfiltered error message from an errored EventBridge put request.
changeEvent
The requested change to your data made by EventBridge. For more information on types of change events and their configurations, see Change Event Types.
Error Codes
If an error was recevied from EventBridge, the event processor will parse the
error as either DOCUMENT_TOO_LARGE
or OTHER
. This parsed error is passed
to the error handler function through the error
parameter.
DOCUMENT_TOO_LARGE
If the put entry for an EventBridge trigger event is larger than 256 KB, EventBridge will throw an error. The error will contain either:
status code: 400 and
total size of the entries in the request is over the limit
.status code: 413, which indicates a too large payload.
For more information on reducing put entry size, see the below Performance Optimization section.
OTHER
The default bucket for all other errors.
Tip
Optimize Error Handling for Errors with OTHER Code
You can make special error handling cases for
your most common error messages to optimize your error handling for
errors with an OTHER
code. To determine which errors need
special cases, we recommended keeping track of
the most common error messages you receive in error.message
.
Error Handler Logs
You can view Trigger Error Handler logs for your EventBridge Trigger error handler in the application logs.
To learn more about viewing application logs, see View Application Logs.
Example Event
The following object configures a trigger to send events to AWS Eventbridge and handle errors:
"event_processors": { "AWS_EVENTBRIDGE": { "config": { "account_id": "012345678901", "region": "us-east-1" } } }, "error_handler": { "config": { "enabled": true, "function_name": "myErrorHandler.js" } }
Performance Optimization
The AWS put entry for an EventBridge trigger event must be smaller than 256 KB.
For more information, see the AWS Documentation to calculate Amazon PutEvents event entry size.
When using Database Triggers, the Project Expression can be useful reduce the document size before sending messages to EventBridge. This expression lets you include only specified fields, reducing document size.
Learn more in the Database Trigger Project Expression documentation.