Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda invocation loop rework #8970

Merged
merged 110 commits into from Sep 12, 2023
Merged

Lambda invocation loop rework #8970

merged 110 commits into from Sep 12, 2023

Conversation

joe4dev
Copy link
Member

@joe4dev joe4dev commented Aug 23, 2023

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
Copy link

github-actions bot commented Aug 23, 2023

LocalStack Community integration with Pro

       2 files         2 suites   1h 22m 58s ⏱️
2 193 tests 1 706 ✔️ 487 💤 0
2 194 runs  1 706 ✔️ 488 💤 0

Results for commit 1ec503f.

♻️ This comment has been updated with latest results.

@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
Copy link

coveralls commented Aug 31, 2023

Coverage Status

coverage: 79.839% (+0.2%) from 79.684% when pulling 1ec503f on lambda-invocation-loop-rework into a9a0668 on master.

@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
Copy link
Member

@dominikschubert dominikschubert left a comment

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 join this conversation on GitHub. Already have an account? Sign in to comment
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.

None yet

4 participants