Triggers in Yandex API Gateway. Overview
A trigger is a condition, upon meeting which an automatic message is sent to WebSocket connections connected to the API gateway at the path specified by the user. The API gateway itself is not called.
A single trigger can simultaneously send messages to WebSocket connections of multiple API gateways, as well as invoke Cloud Functions and Serverless Containers.
Triggers allow you to automate your work with other Yandex Cloud services, such as Yandex Object Storage, Yandex Message Queue, and Yandex Container Registry.
Note
The trigger is initiated within five minutes after it is created.
The following types of triggers are available in Yandex API Gateway:
- Timer
- Trigger for Message Queue
- Trigger for Object Storage
- Trigger for Container Registry
- Trigger for Cloud Logging
- Trigger for Yandex IoT Core
- Trigger for budgets
- Trigger for Data Streams
- Email trigger
- Trigger for Telegram
Each trigger type has its own conditions. For example, a trigger for Object Storage may fire when an object is created or updated. You can set some conditions in the service object settings, e.g., notification thresholds in the budget settings would act as trigger conditions for budgets.
Things to consider about trigger messages
Triggers send messages based on preset quotas and limits.
You need to consider the following points:
- The trigger reformats messages before sending them to WebSocket connections. Each trigger type uses a message format of its own. Read more about this in the relevant trigger description.
- If sending fails or the path specified in the trigger settings has no clients connected, the message gets lost and resending is not possible.
- The service account you are going to use to send messages to WebSocket connections must have the
functions.functionInvokerrole. Other roles required for the trigger to operate correctly depend on trigger type. For more details, see the relevant trigger description.
Filtering events
You can configure a filter for each resource invoked in a trigger. The filter is a jq expression
true, the event is forwarded to the target.falseor if the event fails to parse, the event is dropped and not sent.
Filters are defined separately for each target, i.e., a single trigger can deliver different events to different targets. If no filter is set, all events are sent to the target.
Transforming events
For each target in a trigger, you can specify a jq
- Convert the event to the format expected by the target.
- Keep only the required fields in the event.
- Add custom fields and values to the event.
The template is defined separately for each target, so one trigger can send different representations of the same event to different targets. If no template is specified, the event is sent to the target as is.
Event batching
The batching settings allow you to send several events to a target at the same time. They set a top limit on the event batch size and accumulation time. For example, if the event batch size is 3, the target can receive batches of one to three events.
You can configure the following triggers to batch events before sending them to a target:
- Trigger for Message Queue.
- Trigger for Cloud Logging.
- Trigger for Object Storage.
- Trigger for Container Registry.
- Trigger for Yandex IoT Core.
- Trigger for Data Streams.
- Email trigger.
- Trigger for Telegram.