Lambda invocation loop rework by joe4dev · Pull Request #8970 · localstack/localstack · GitHub
Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Lambda invocation loop rework#8970

Merged
joe4dev merged 110 commits into
masterfrom
lambda-invocation-loop-rework
Sep 12, 2023
Merged

Lambda invocation loop rework#8970
joe4dev merged 110 commits into
masterfrom
lambda-invocation-loop-rework

Conversation

@joe4dev

@joe4dev joe4dev commented Aug 23, 2023

Copy link
Copy Markdown
Member

Motivation

  • Fixes the infinite Lambda re-spawn loop: Whenever a Lambda environment fails to start (e.g., even due to common user errors), the Lambda container enters an infinite retry loop instead of reporting an appropriate error message and stopping retries (depending on the error cause). This behavior is user-unfriendly and affects many GitHub issues and support tickets.
  • Architecture mismatch between LocalStack and real AWS Lambda: The architectural mismatch causes parity issues, impedes debugging, and complicates adding new features.

Goals

  • Core loop: The default invocation path should be synchronous instead of asynchronous. This enables improved error handling and better AWS parity.
  • Environment management: Allow for more explicit control over execution environments. This unblocks custom workers.
  • Asynchronous event invocation: Separate asynchronous event invocations and handle retries, DLQs, and event destinations properly. This fixes bugs and increases AWS parity.
  • Encapsulate concurrency logic: The logic related to concurrency management should be better encapsulated rather than scattered throughout an implicit and complex control flow through an asynchronous invocation loop. This enables better AWS parity and makes improving and adding features easier.

Changes

This PR basically re-writes the data plane (i.e., everything related to environment assignment and invocation scheduling) of our new Lambda provider. The re-architected implementation is inspired based on the real architecture of AWS Lambda explained at AWS re:Invent 2022 - A closer look at AWS Lambda (SVS404-R).

Invocation model

image

Images from AWS: https://youtu.be/0_jfH6qijVY

Synchronous invocation

image

Asynchronous Invocation

image

More details to follow ...

Internal Documentation

Testing

This PR adds more AWS-validated tests and fixes some existing tests (e.g., fixes timing assumptions, and makes async tests faster). One example: We previously triggered the DLQ destination upon every failed invocation rather than only after the last retry.

TODO

See internal documentation Collection of Meeting Notes (Notion)

@joe4dev joe4dev added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Aug 23, 2023
@joe4dev joe4dev added this to the 2.3 milestone Aug 23, 2023
@github-actions

github-actions Bot commented Aug 23, 2023

Copy link
Copy Markdown

@joe4dev joe4dev force-pushed the lambda-invocation-loop-rework branch 4 times, most recently from 79a7c08 to 0c0e31f Compare August 31, 2023 08:30
@coveralls

coveralls commented Aug 31, 2023

Copy link
Copy Markdown

@joe4dev joe4dev force-pushed the lambda-invocation-loop-rework branch 5 times, most recently from 91b8a32 to 46a4a46 Compare September 5, 2023 09:38
@joe4dev joe4dev force-pushed the lambda-invocation-loop-rework branch from 994726e to 463a67f Compare September 7, 2023 10:16
@joe4dev joe4dev marked this pull request as ready for review September 12, 2023 11:29

@dominikschubert dominikschubert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants