SQS Triggers
Orvanta can connect to an SQS queue and trigger runnables (scripts, flows) in response to messages received.
SQS triggers is a self-hosted Enterprise feature.
How to use
Section titled “How to use”-
Pick an AWS or AWS OIDC resource
- Select an existing AWS resource or AWS OIDC resource or create a new one.
- The AWS resource must have permissions to interact with SQS.
-
Select the runnable to execute
- Choose the runnable (script or flow) that should be executed when a message arrives in the queue.
-
Provide an SQS queue URL
- Enter the Queue URL of the SQS queue that should trigger the runnable.
- You can find the Queue URL in the AWS Management Console under SQS.
- For more details, see the SQS Queue URL documentation.
-
Choose (optional) message attributes
- Specify which message attributes should be included in the triggered event.
- These attributes can carry metadata, such as sender information or priority levels.
- For more details, see the SQS Message Attributes documentation.
Example
Section titled “Example”Basic script example
Section titled “Basic script example”export async function main(msg: string) { // do something with the message}Using a preprocessor
Section titled “Using a preprocessor”If you use a preprocessor, the preprocessor function receives an SQS message with the following fields:
Field descriptions
Section titled “Field descriptions”queue_url: The URL of the SQS queue that received the message.message_id: A unique identifier assigned to each message by SQS.receipt_handle: A token used to delete the message after processing.attributes: Metadata attributes set by SQS, such asSentTimestamp.message_attributes: User-defined attributes that can be attached to the message.string_value: The string representation of the attribute value.data_type: The data type of the attribute (e.g.,"String","Number","Binary").
export async function preprocessor( event: { kind: "sqs", msg: string, queue_url: string, message_id?: string, receipt_handle?: string, attributes: Record<string, string>, message_attributes?: Record<string, { string_value?: string, data_type: string }> }) { if (event.kind !== "sqs") { throw new Error(`Expected a SQS event`); } // assuming the message is a JSON object const data = JSON.parse(event.msg);
return { content: data.content, metadata: { sentAt: event.attributes.SentTimestamp, messageId: event.message_id } };}
export async function main(content: string, metadata: { sentAt: string, messageId: string }) { // Process transformed message data console.log(`Processing message ${metadata.messageId} sent at ${metadata.sentAt}`); console.log("Content:", content);}Error handling
Section titled “Error handling”SQS triggers support local error handlers that override workspace error handlers for specific triggers. See the error handling documentation for configuration details and examples.