Skip to content

New pattern submission: apigw-lambda-durable-tenant-isolation-callback-terraform #3170

Description

@Anandoo7

To submit a template to the Serverless Patterns Collection, submit an issue with the following information.

IMPORTANT
Patterns are intended to be primarily IaC-focused implementations of 2-4 AWS services, with minimum custom code. They should be commonly used combinations that help developers get started quickly. If you have a utility, demo, or application, submit these to the Serverless Repos Collection instead.

ONLY SUBMIT ONE PATTERN CHANGE PER PR. Multiple patterns or files spanning multiple pattern directories will be automatically rejected.

Patterns may take up to 4-6 weeks to review, test, and merge but there is no SLA and can take significantly longer due to other work the team has.

To learn more about submitting a pattern, read the publishing guidelines page.

Use the model template located at https://github.com/aws-samples/serverless-patterns/tree/main/_pattern-model to set up a README, template and any associated code.

THIS PROCESS HAS BEEN SIMPLIFIED. All the information below must be provided in the "example-pattern.json" file cloned from the model **

Description:

SaaS applications often process tenant requests that cannot complete in a single invocation. The workflow must pause and wait for an external system to respond — a payment gateway confirming a charge, a compliance system returning a decision, or a human approver acting on a request. During this wait, the first processing step has already validated the request and cached tenant-specific data in the execution environment's memory: configuration, credentials, computed intermediate results.

This pattern uses Lambda durable functions to suspend the workflow at zero compute cost and resume from a checkpoint when the external confirmation arrives, without re-executing completed work. It uses Lambda tenant isolation mode to ensure that the suspended execution environment — including all cached in-memory state from the first step — is never reassigned to another tenant during the wait period. Without per-tenant isolation, a different tenant's invocation could be routed to the same suspended environment, exposing one tenant's cached data to another. Without durable execution, the function cannot suspend and resume across the wait boundary, forcing you to externalize all intermediate state to a database and build a separate mechanism to trigger resumption.

The pattern deploys two API Gateway endpoints backed by two Lambda functions. The /workflow endpoint starts a durable workflow for a specific tenant — API Gateway maps the x-tenant-id header to a tenant-dedicated execution environment. The function validates the request, checkpoints progress, and suspends while logging a callback token. When the external system confirms the operation, it sends the token to the /callback endpoint, which resumes the workflow from its checkpoint. The resumed function skips all previously completed work and finishes processing with the confirmation payload. Multiple tenants can have workflows suspended simultaneously, each in a dedicated execution environment, each resuming independently when its own callback arrives.

Resources:

https://docs.aws.amazon.com/lambda/latest/dg/durable-functions.html
https://docs.aws.amazon.com/lambda/latest/dg/tenant-isolation.html

Framework: Terraform

Author Bio:

Name: Annangarachari R
Image: https://media.licdn.com/dms/image/v2/C5603AQHDdhBrpBtWsg/profile-displayphoto-shrink_800_800/profile-displayphoto-shrink_800_800/0/1651409742725?e=1759363200&v=beta&t=7-EnqmtXjWlH2uA8oSMCwnLfFFvlWtf42-aC8NSZukw
Bio: Serverless Enthusiast
linkedin: https://www.linkedin.com/in/annangarachari-r/

You must ensure that the sections of the model README.md are completed in full.

GitHub PR for template: #3169

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions