Skip to content

Latest commit

 

History

History
89 lines (63 loc) · 4.35 KB

File metadata and controls

89 lines (63 loc) · 4.35 KB

Lambda durable functions invoking AWS Lambda function (Python)

This pattern demonstrates how an AWS Lambda durable function can invoke a standard AWS Lambda function using context.invoke() from the durable execution SDK. The invocation is automatically checkpointed, so if the durable function is interrupted after the invoked function completes, it resumes with the stored result without re-invoking the target function.

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/lambda-durable-invoke-lambda-sam-python

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

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:

    git clone https://github.com/aws-samples/serverless-patterns
    
  2. Change directory to the pattern directory:

    cd lambda-durable-invoke-lambda-sam-python
    
  3. From the command line, use AWS SAM to build and deploy the AWS resources for the pattern as specified in the template.yaml file:

    sam build
    sam deploy --guided
    
  4. During the prompts:

    • Enter a stack name
    • Enter the desired AWS Region (durable functions are available in supported regions)
    • Allow SAM CLI to create IAM roles with the required permissions.

    Once you have run sam deploy --guided mode once and saved arguments to a configuration file (samconfig.toml), you can use sam deploy in future to use these defaults.

  5. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.

How it works

This pattern deploys two Lambda functions:

  1. DurableLambdaFunction - A durable Lambda function that orchestrates the workflow. It uses the @durable_execution decorator and performs two checkpointed operations:

    • A @durable_step that prepares and validates input values.
    • A context.invoke() call that invokes the ProcessorFunction and waits for its result.
  2. ProcessorFunction - A standard Lambda function that receives a list of numeric values and returns computed statistics (sum, average, max, min).

The AWS Lambda durable function uses automatic checkpointing. Each step and invoke operation creates a checkpoint. If the function is interrupted (e.g., due to a transient failure), it replays from the beginning but skips completed checkpoints, resuming execution from where it left off.

Testing

  1. After deployment, invoke the durable function using the alias ARN from the stack outputs:

    aws lambda invoke \
      --function-name <DurableLambdaFunctionAliasArn> \
      --payload '{"values": [10, 20, 30, 40, 50]}' \
      --cli-binary-format raw-in-base64-out \
      output.json
  2. Check the response:

    cat output.json

    Expected output:

    {"statusCode": 200, "body": "{\"message\": \"Durable orchestration completed successfully\", \"input_values\": [10, 20, 30, 40, 50], \"processing_result\": {\"operation\": \"sum_and_average\", \"count\": 5, \"sum\": 150, \"average\": 30.0, \"max\": 50, \"min\": 10}}"}
  3. Monitor the durable execution steps in the Lambda console under the Durable executions tab of the DurableLambdaFunction.

Cleanup

  1. Delete the stack
    sam delete

Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0