AWS Builder Center
How to Route Website Leads to the Right Sales Team with DynamoDB Streams and AWS Lambda

How to Route Website Leads to the Right Sales Team with DynamoDB Streams and AWS Lambda

Route captured website leads to the right sales queue using DynamoDB Streams and AWS Lambda. Handle overlapping rules, manual assignments, and delayed CRM updates.

Love to Learn Tech especially AI things.
A company captures every website enquiry in DynamoDB. Its sales team still misses good opportunities because all submissions go to a shared inbox. A HubSpot migration request, a custom CRM project, and a vague “please call me” message arrive in the same queue.
Lead capture answers whether the enquiry was saved. Lead routing answers who is responsible for it.
This example adds routing to an existing website lead-capture workflow. It uses DynamoDB Streams to trigger a Lambda worker after the enquiry is saved, then records the sales assignment before syncing it to a CRM.

1. Start with a short, ordered rule list

Use fields the form collects explicitly. For this example, the website records an optional CRM platform and request type, both normalized to known values.
Priority
Condition
Destination
1
Platform is HubSpot or Zoho and request type is migration or integration
CRM integrations queue
2
Request type is custom CRM development
Custom solutions queue
3
No rule matches or routing inputs are missing
Sales triage queue
Evaluate rules in priority order. A visitor who selects HubSpot integration and mentions custom reporting in the message still goes to the integrations queue under this policy.
Start with team queues so someone can pick up enquiries when an individual representative is unavailable. Keep the routing reason on the lead so sales can explain or correct the assignment.

2. Store the assignment before sending it to the CRM

Configure the worker to act on new lead inserts. If the same DynamoDB stream also contains updates made by the worker, filter those updates out of the routing path.
A routing decision might look like this:
{
"submissionId": "lead_7a93",
"assignmentStatus": "ASSIGNED",
"assignedQueue": "CRM_INTEGRATIONS",
"assignmentSource": "AUTO",
"assignmentVersion": 1,
"routingReason": "PLATFORM_INTEGRATION",
"rulesVersion": "2026-11"
}
Apply the decision with a conditional write that requires the lead to still be  UNASSIGNED . If the routing event arrives twice, only the first valid assignment wins. If a salesperson has already assigned the lead manually, the automated update cannot replace that decision.
Save the assignment and a pending CRM sync job together in a transaction. This lets the sales team see the routing decision even if the external CRM is temporarily unavailable.

3. Make CRM sync safe to retry

Use the original submission ID as the external lead reference wherever the CRM supports an upsert or a unique external identifier. Use the assignment version to identify each ownership change.
Suppose the first sync job assigns a lead to CRM Integrations. A salesperson then moves it to Custom Solutions, creating assignment version 2. If version 1 is retried later, the sync worker should compare it with the current assignment and skip the stale job.
If both versions can be in flight at once, serialize CRM updates per lead or use a destination-side version check where supported. A local version check by itself cannot prevent an older request that is already in flight from arriving last.
Track CRM sync separately from assignment. An assigned lead can still be awaiting sync, and support staff should be able to see that distinction.

4. Test the cases sales will notice

Scenario
Expected result
Lead asks for a Zoho migration
It lands in CRM Integrations with a recorded routing reason
Lead has no platform or request type
It lands in Sales Triage
The insert event is processed twice
One initial assignment is stored
Sales assigns the lead before Lambda runs
The manual assignment is preserved
The CRM times out after receiving the lead
A retry uses the same external lead reference
An older sync job runs after a reassignment
It cannot overwrite the newer owner under the chosen sync design
Monitor the age of the oldest unassigned lead, the percentage routed to triage, and the number of assignments waiting for CRM sync. A growing triage queue can reveal a missing form field or a gap in the routing rules. A growing sync backlog points to a delivery problem after assignment.
The first release only needs to answer three questions consistently: where did the enquiry go, why did it go there, and has the CRM received the latest assignment?
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article