Skip to content

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Mar 17, 2025

Motivation

As reported by #12390, when evaluate large payload for PutEvents, LocalStack would fail. I could reproduce the issue and saw LocalStack consumes as much as 20GB of memory while trying to evaluate the payload given by the user.
This payload was very complex, with lots of nested dictionaries and list. List are "exploding" the complexity, creating "or" conditions and new "branches" to evaluate.

This is because we're using recursion to evaluate EventPattern against payload, and we would try to get the event payload in a flat shape to be able to be evaluated against the Pattern (due to how AWS treats the . notation).

I've added some conditions checks to only evaluate the payload when relevant to the Event Pattern, and to not evaluate "branches" of the payload. This fixes the issue and the memory usage, as payloads now stay "simple" and without the bounds.

I've also added some small unit tests because the doc strings were getting a bit too big to explain all the behavior.

\cc @cloutierMat as we worked on this together for SNS

fixes #12390

See https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-pattern.html

Reading again, this should have been considered from the start with the following (my bad!):

EventBridge ignores the fields in the event that aren't included in the event pattern.

Changes

  • add a check to not evaluate the payload "branch" if not relevant to the pattern

We will need to port this fix to the SNS Filter policy engine as well, I'll tackle that in a follow up.

@bentsku bentsku added aws:events Amazon EventBridge semver: patch Non-breaking changes which can be included in patch releases labels Mar 17, 2025
@bentsku bentsku added this to the 4.3 milestone Mar 17, 2025
@bentsku bentsku self-assigned this Mar 17, 2025
@bentsku bentsku requested a review from maxhoheiser as a code owner March 17, 2025 12:00
@bentsku bentsku force-pushed the improve-event-ruler branch from c6f2314 to 4e97e2f Compare March 17, 2025 12:01
Copy link
Member

@maxhoheiser maxhoheiser left a comment

Choose a reason for hiding this comment

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

LGTMT - nice and quick fix for the large payload problem ! 👍

Copy link

LocalStack Community integration with Pro

    2 files  ±    0      2 suites  ±0   1h 8m 18s ⏱️ - 43m 14s
2 521 tests  - 1 768  2 416 ✅  - 1 553  105 💤  - 215  0 ❌ ±0 
2 523 runs   - 1 768  2 416 ✅  - 1 553  107 💤  - 215  0 ❌ ±0 

Results for commit 4e97e2f. ± Comparison against base commit 30940d8.

This pull request removes 1769 and adds 1 tests. Note that renamed tests count towards both.
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_lambda_dynamodb
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_opensearch_crud
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_search_books
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_setup
tests.aws.scenario.kinesis_firehose.test_kinesis_firehose.TestKinesisFirehoseScenario ‑ test_kinesis_firehose_s3
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_destination_sns
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_infra
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_prefill_dynamodb_table
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input0-SUCCEEDED]
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input1-SUCCEEDED]
…
tests.aws.services.events.test_events_patterns.TestEventPattern ‑ test_event_with_large_and_complex_payload

@bentsku bentsku merged commit a48f50c into master Mar 17, 2025
43 checks passed
@bentsku bentsku deleted the improve-event-ruler branch March 17, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:events Amazon EventBridge semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: EventBridge PutEvents call with a payload of 40KB crashes LocalStack
2 participants