Integrating Generative AI Through Events
This lesson covers EventBridge, queues and webhook handlers, which let generative AI react to business events without tight coupling to the systems that produce them.
Learning outcomes
After completing this lesson, you will be able to:
- Decouple producers from FM processing with EventBridge.
- Handle SaaS webhooks securely.
- Package capabilities as microservices behind API Gateway.
Amazon EventBridge for loose coupling
Amazon EventBridge event buses receive events from AWS services, custom applications and SaaS partners. Rules match events by pattern, such as a new support ticket with priority high, and route them to targets: a Lambda function that summarises the ticket, a Step Functions workflow that drafts a response, or an SQS queue that buffers work. Producers publish events once, and new generative AI consumers can be added without changing them. EventBridge Pipes connect sources such as SQS, Kinesis or DynamoDB Streams to targets with filtering and enrichment, and EventBridge Scheduler triggers scheduled processing.
Results flow back as new events, such as TicketSummarized, which other systems consume. This pattern keeps slow, variable FM latency out of the producer's critical path and lets failures be retried independently, with archives and replay for recovery.
The following diagram shows the event-driven path.

EventBridge features
Webhook handlers
Many SaaS products notify integrations through webhooks: HTTP POST requests when something happens. A Lambda function URL or an API Gateway endpoint receives the webhook. The handler should verify the sender's signature (with the secret in AWS Secrets Manager), validate the payload, respond quickly with HTTP 200 so the sender does not retry, and hand the work to an SQS queue or EventBridge for asynchronous FM processing. Deduplicating by event ID handles senders' retries.
def handler(event, context):
body = event["body"]
if not valid_signature(body, event["headers"].get("x-signature"), get_secret("crm-webhook")):
return {"statusCode": 401}
payload = json.loads(body)
events.put_events(Entries=[{"Source": "crm.webhook", "DetailType": "OpportunityUpdated",
"Detail": json.dumps(payload), "EventBusName": "business-events"}])
return {"statusCode": 200} # acknowledge fast; FM processing happens asynchronouslyThe following diagram shows the steps a webhook handler takes before any model call.

A robust webhook handler
Microservice integration with API Gateway
Generative AI capabilities are often packaged as microservices behind Amazon API Gateway, such as a summarisation service, a classification service and a draft-reply service. Each has its own model, prompt, scaling settings and team ownership, and each can be changed or scaled without affecting the others or the applications that call them.
Existing applications call these services synchronously when a user is waiting for the result, while event-driven flows call them from Lambda functions or Step Functions workflows when work can happen in the background. Exposing the capabilities as services with stable APIs also means that the model or prompt behind a service can change without any change to its callers. The following table summarises the integration styles.
| Style | Mechanism | Use when |
|---|---|---|
| Event-driven | EventBridge rules and targets | React to business events; many consumers |
| Queued | SQS with workers | Buffer bursts; control throughput |
| Webhook | Lambda function URL or API Gateway | SaaS notifications; acknowledge fast |
| Request-response microservice | API Gateway with Lambda or containers | Interactive features in existing apps |
| Scheduled | EventBridge Scheduler | Periodic summaries, refreshes and reports |
Summarising new tickets
A ticketing system should attach an AI summary and suggested category to every new ticket. Calls from the ticketing system to the model currently block ticket creation for several seconds and fail when the model is throttled.
Instead, ticket creation publishes a TicketCreated event to EventBridge; a rule targets an SQS queue; a Lambda worker summarises and categorises the ticket and updates it through the ticketing API. Ticket creation is no longer blocked, and throttled requests are retried from the queue.
Why should a webhook handler acknowledge quickly and process asynchronously?
Show answer
Model calls are slow, and the sender may time out and retry, causing duplicates.
Exam Tips
Remember for the exam
- EventBridge rules decouple business events from FM processing.
- Webhook handlers: verify signature, acknowledge fast, process asynchronously.
- Expose generative AI features as API Gateway microservices.
- Keep FM latency out of producers' critical paths.