An extra 30% off every course until Sunday, October 11.Choose your certification →

Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

4.2.1. Event-Driven and Microservice Integration

💡 First Principle: Loose coupling between GenAI components and enterprise systems via events and APIs means a model update, a RAG pipeline change, or a provider switch has zero impact on consuming applications — they never know what's behind the integration surface.

Event-driven GenAI integration with EventBridge:
Webhook integration for real-time FM triggers:
# API Gateway → Lambda webhook: triggered by external system events
def lambda_handler(event, context):
    body = json.loads(event['body'])
    
    # Validate webhook signature (security)
    if not validate_hmac(event['headers'], body):
        return {'statusCode': 401, 'body': 'Unauthorized'}
    
    # Async processing: send to SQS to decouple processing from response
    sqs.send_message(
        QueueUrl=PROCESSING_QUEUE_URL,
        MessageBody=json.dumps({
            'type': body['event_type'],
            'payload': body['data'],
            'received_at': datetime.utcnow().isoformat()
        })
    )
    
    # Return immediately — don't make caller wait for FM processing
    return {'statusCode': 202, 'body': json.dumps({'status': 'accepted'})}

Adding GenAI to an existing API: add it as a new route (for example /ai) backed by its own Lambda function, so existing routes and consumers are untouched. Forking the codebase, migrating the whole API, or folding existing handlers into one GenAI function all disrupt current consumers.

Pattern decision: sync vs. async FM integration:
PatternWhen to UseAWS Services
SynchronousUser waiting for response; SLA < 30sAPI Gateway → Lambda → Bedrock
AsynchronousBackground processing; no waiting; SLA in minutesSQS → Lambda → Bedrock → SNS notify
StreamingProgressive display; long-form generationAPI Gateway WebSocket → Lambda → Bedrock streaming
BatchNightly processing; cost optimizationS3 event → Lambda batch → Bedrock → S3 output

Fan-out for bulk or oversized work: when one event carries thousands of documents, or one document takes longer than Lambda's 15-minute maximum, split the work into one SQS message per document (or per page or chunk) and let Lambda consumers process them in parallel; the SQS event source scales consumers with queue depth. More memory, a longer timeout, or a single function looping over everything does not remove the 15-minute ceiling.

⚠️ Exam Trap: API Gateway has a maximum integration timeout of 29 seconds. Long-context Bedrock calls that take 30+ seconds will cause API Gateway to return a 504 timeout to the client even if the Lambda and Bedrock call eventually succeed. For long-running FM calls, use an async pattern (SQS + polling or WebSocket) rather than a synchronous API Gateway integration.

Reflection Question: Your enterprise system needs to generate AI summaries for every new Salesforce opportunity created. The sales team expects summaries to appear within 5 minutes of opportunity creation. What event-driven architecture would you implement, and why would you choose async over sync?

See how it connects
Alvin Varughese
Written byAlvin Varughese
Founder•20 professional certifications