Skip to main content

AWS SQS order → persistence and notification

This workflow consumes the messages from an Amazon SQS queue, records each order in PostgreSQL, notifies management for high amounts and forwards the order to the ERP.

Loading the diagram…

The need​

Each order received on an Amazon SQS queue must be recorded in PostgreSQL to serve as a reference. High amounts must notify management, and each order must be forwarded to the ERP for accounting processing. If recording fails, the technical team must be alerted.

What the workflow does​

  1. Order received (SQS) — the AWS SQS Trigger node starts an execution for each message received in the queue. The order data arrives in data.
  2. Record the order — the PostgreSQL node inserts the row in the commandes table using bound parameters ($1, $2, …).
  3. High amount? — the Condition node compares {{ data.montant }} to the 500 threshold.
  4. Notify management — if the amount exceeds the threshold, an email is sent to management.
  5. Forward to the ERP — the Send AWS SQS node publishes the order in the ERP queue for accounting processing.
  6. Handle SQL failure — if the PostgreSQL node errors, the On Error node takes over, then Alert the technical team sends an email to the internal teams.

What you need​

Construction​

Copy the workflow definition and paste it into the editor (the Trigger node is recreated automatically, it is not in the snippet):

[
{
"id": "db-104",
"name": "Record the order",
"config": {
"type": "DATABASE_POSTGRESQL",
"query": "INSERT INTO commandes (reference, amount, customer) VALUES ($1, $2, $3) RETURNING id",
"binds": [
"$.data.reference",
"$.data.montant",
"$.data.client"
],
"outputKey": "orderResult"
},
"parents": [
"trigger"
],
"position": {
"x": 0,
"y": 200
},
"next": "cond-104"
},
{
"id": "cond-104",
"name": "High amount?",
"config": {
"type": "CONDITION",
"conditionCode": "return data.montant > 500;",
"conditions": [
{
"value": true,
"next": "email-104"
},
{
"value": false,
"next": null
}
]
},
"parents": [
"db-104"
],
"position": {
"x": 0,
"y": 400
}
},
{
"id": "email-104",
"name": "Notify management",
"config": {
"type": "SEND_EMAIL",
"to": [
"direction@boutique-france.fr"
],
"subject": "High order: {{ data.montant }} €",
"content": "An order of {{ data.montant }} € has been recorded (ref. {{ data.reference }}).",
"sendAsHtml": true
},
"parents": [
"cond-104"
],
"position": {
"x": 0,
"y": 600
},
"next": "sqs-104"
},
{
"id": "sqs-104",
"name": "Forward to the ERP",
"config": {
"type": "SEND_AWS_SQS",
"region": "eu-west-1",
"queue": {
"type": "STANDARD",
"url": "https://sqs.eu-west-1.amazonaws.com/123456789012/orders-erp",
"messageBody": "{\"reference\": \"{{ data.reference }}\", \"amount\": \"{{ data.montant }}\"}"
}
},
"parents": [
"email-104"
],
"position": {
"x": 0,
"y": 800
}
},
{
"id": "error-104",
"name": "Handle SQL failure",
"config": {
"type": "ON_ERROR",
"enabledEnvironments": []
},
"parents": [],
"position": {
"x": -800,
"y": 0
},
"next": "error-email-104"
},
{
"id": "error-email-104",
"name": "Alert the technical team",
"config": {
"type": "SEND_EMAIL",
"to": [
"ops@boutique-france.fr"
],
"subject": "SQL failure: order {{ data.reference }}",
"content": "The insertion of order {{ data.reference }} failed in the database.",
"sendAsHtml": true
},
"parents": [
"error-104"
],
"position": {
"x": -800,
"y": 200
}
}
]

Check that it works​

The trigger payload must expose the order fields used by the workflow (reference, montant), otherwise the {{ data… }} fields will remain empty. Deploy the workflow, start an execution and check the traces to verify that the order is recorded, the notification is sent for high amounts and the order is forwarded to the ERP.

Variations​

  • Threshold: the value 500 is hardcoded in the condition; move it to a dictionary if it must vary without modifying the workflow.
  • Redelivery: configure a Visibility Timeout at least equal to the workflow execution time, otherwise the message can be redelivered — see AWS SQS trigger.
  • Error branch: the On Error node catches the PostgreSQL node error (starting point, without an upstream node); the following steps (Alert the technical team) illustrate the error handling chain to recreate in the editor.
  • Query security: use the parameter binding provided by the PostgreSQL node instead of concatenating values in the query — see PostgreSQL node.

See the reference


See also: Examples and integrations