Generate Sample Payload for a Component Event Source

Payload Generation

A component event listener listens for a specific event occurring in one of the Catalyst components, then triggers the associated target function and passes the component data to it. It is already created by default in a project. You can obtain sample data of the same pattern in the CLI, for the source and the action you require.

The general command to generate a sample payload of an event in the CLI is:

copy
$
catalyst event:generate|generate:event [options] <source> <action>

You can provide any of the sources and associated actions of a Catalyst component event, in the command shown in the table below:

Source Action Optional Inputs
datastore Insert Update Delete --table <table_name_or_id>
cache Put --segment <segment_name_or_id>
user SignUp Delete NA
filestore Upload --folder <folder_name_or_id>
webapp Success NA
github Success Failure NA

For example, to generate a sample payload for a Data Store Insert event, execute the following command:

copy
$
catalyst event:generate|generate:event datastore Insert

This will generate the following JSON payload for this source and action. The payload will contain the actual details of your project, the default event bus details, and sample entity details.

Component Event Payload Generation

You can pass this data to an event function through the functions shell, and test it as per your requirements.


You can also directly save the JSON payload into a file instead of displaying it in the CLI, by creating a file for it in the path you require like:

copy
$
catalyst event:generate|generate:event user Signup>>payload.json

Optional Inputs

In addition to the mandatory source and action pair, you can also supply optional inputs about the entity source, as shown in the table. For example, if you specify the table name or ID while generating the sample payload for a Data Store insert operation, Catalyst will check your remote project for a table with that name or ID. If the entity exists, the CLI will display the data of that table in the JSON payload.

If you do not provide any optional inputs, or if there are no entities to be found matching your inputs, the CLI will generate the JSON payload with random sample data.


For example, to generate a sample payload for a cache put event in an existing segment configured in the remote console, the following command is executed:

copy
$
catalyst event:generate|generate:event cache Put --segment <segment_name_or_id>

Catalyst checks for a segment of that name or ID. If it exists, it will generate the payload including that segment’s data. The Segment ID that was passed is specified as the value for source_entity_id in the example shown below.

Component Event Payload Generation


Component Event Generation Options

The catalyst event:generate command supports two options that you can use it with. However, only one of those options is applicable when you generate a sample payload of a component event source.


-e | --event-bus <event_bus_name>

The --event-bus or -e option enables you to specify the name of the event bus that must be used in the sample payload. You can use this while generating the payload of any source or action. The event_bus_details JSON will contain the name that you pass as the bus’s name.

If you do not specify the event bus name, the bus name will be ‘Default’ in a component event’s payload.


For example, to generate the payload of a cache put event and to specify the event bus name with it, execute the following command:

copy
$
catalyst event:generate|generate:event cache Put --event-bus TrackerRequests

This will generate the payload and include the event bus name in event_bus_details .

Component Event Payload Generation

We will discuss the available options in the context of a custom event source in the next section.

Note: If you are a Visual Studio Code IDE user, you can install the Catalyst Tools extension, and perform CLI operations using your IDE in place of the CLI. Steps to debug your event functions using Visual Studio Code IDE can be found here.

Last Updated 2024-01-09 17:07:13 +0530 +0530