Lesson 1 of 4 Enterprise Integration Architectures

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.

Summarising new tickets without blocking their creation. Ticket creation publishes a TicketCreated event to EventBridge, a rule sends it to an SQS queue, and a Lambda worker summarises and categorises the ticket and updates it through the ticketing API. Throttled requests wait in the queue instead of failing.
New consumers can be added to the event without changing the ticketing system.
Match the pairs

EventBridge features

Exam skills 2.3.1

Match each EventBridge feature with how it is used in a GenAI integration.

Log in to try this activity Interactive activities are free with an account.

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 asynchronously

The following diagram shows the steps a webhook handler takes before any model call.

A webhook handler for FM processing. A Lambda function URL or API Gateway endpoint receives the SaaS product's POST; the handler verifies the signature with a secret from Secrets Manager, validates the payload, deduplicates by event ID and responds 200 quickly, then hands the work to SQS or EventBridge for asynchronous processing.
Responding quickly stops the sender from retrying the delivery.
Select all that apply

A robust webhook handler

Exam skills 2.3.1 · 2.5.3

A SaaS ticketing system calls a Lambda function URL whenever a ticket is created, and each ticket is summarised by an FM. Choose the practices the handler should follow.

Log in to try this activity Interactive activities are free with an account.

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.

StyleMechanismUse when
Event-drivenEventBridge rules and targetsReact to business events; many consumers
QueuedSQS with workersBuffer bursts; control throughput
WebhookLambda function URL or API GatewaySaaS notifications; acknowledge fast
Request-response microserviceAPI Gateway with Lambda or containersInteractive features in existing apps
ScheduledEventBridge SchedulerPeriodic summaries, refreshes and reports
Worked example

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.

Check yourself

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.