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'})}
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

⚠️ 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?

Alvin Varughese
Written byAlvin Varughese
Founder15 professional certifications