Skip to content

Latest commit

 

History

History
67 lines (47 loc) · 2.51 KB

File metadata and controls

67 lines (47 loc) · 2.51 KB

AWS Lambda Tenant Isolation with SQS

This pattern demonstrate AWS Lambda's tenant isolation feature in Multi-tenant application. It uses single SQS for multi-tenant applucation and isolating messages using messagegroupid and invoking isolated lambda enviornments.

Key Features

  • Tenant isolation at infrastructure level (no custom routing logic)
  • Execution environments never shared between tenants
  • Asynchronous invocation pattern
  • Automatic tenant context propagation

Learn more about this pattern at Serverless Land Patterns

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

Requirements

Components

1. SQS Processor (sqs-processor/)

  • Triggered by SQS queue messages
  • Extracts customer-id from message payload
  • Invokes tenant-isolated Lambda asynchronously with TenantId parameter

2. Tenant-Isolated Processor (tenant-isolated-processor/)

  • Configured with tenant isolation mode enabled
  • Processes requests in isolated execution environments per tenant
  • Accesses tenant ID via context.identity.tenant_id

Message Format

{
  "data": "your payload here"
}

Deployment Instructions

sam build
sam deploy --guided

How it works

SQS Queue → SQS Processor Lambda → Tenant-Isolated Lambda
            (reads customer-id)     (processes with tenant isolation)

Testing

Send a message to the SQS queue:

aws sqs send-message \
  --queue-url <QUEUE_URL> \
  --message-body '{"data": "test payload"}'

After dropping the message, review cloudwatch log for Tenant-Isolated Lambda. Different log streams should be created for each tenant.