Skip to content

bug: EventBridge v2 put events returns duplicated EventId in case matching more than one rule and target #11597

@artur-nogueira

Description

@artur-nogueira

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Hello

I apologise in advance if this is already an unknown issue, but I haven't found a related thread.

I found a small bug while using localstack (v 3.7.2) with EventBridge v2. I've noticed the response from PutEventsCommand for valid events includes the EventId for every matched rule and respective targets, when it should only return once even if multiple rules match that dispatched event. This is visible when we handle the SDK response to match the input events by the ID for example.

I think the code line in question is this one link.

Expected Behavior

The expected behaviour of the Put Events response should return the respective ID of each event (while preserving order) only once regardless if there are multiple matched rules/targets.

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

I run localstack version 3.7.2 using docker compose.

docker-compose.yml:

services:
  localstack:
    image: localstack/localstack:3.7.2
    container_name: test-localstack
    ports:
      - '4566:4566' # LocalStack Gateway
      - '4510-4559:4510-4559' # external services port range
    networks:
      - service-net
    environment:
      - DEBUG=1 # Debug level 1 if you want to logs, 0 if you want to disable
      - START_WEB=0 # Flag to control whether the Web UI should be started in Docker
      - DOCKER_HOST=unix:///var/run/docker.sock
      - DATA_DIR=/tmp/localstack/data #  Local directory for saving persistent data(Example: es storage)
      - DEFAULT_REGION=eu-west-1
      - PROVIDER_OVERRIDE_EVENTS=v2
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'

networks:
  service-net:

Start container with docker compose up

For the following example, I'm using the CLI to create two event rules for the same detail type. And each event rule has two targets (a mock SQS queue). Then, I perform a put events which will return the same EventId 4 times in this case (2 rules * 2 targets).

  1. Create a mock SQS to be used as rules target
    aws sqs create-queue --queue-name test-queue --endpoint-url http://localhost:4566

  2. Create two event rules

  • aws events put-rule --name rule-duplicated1 --event-pattern "{\"source\": [\"test\"], \"detail-type\":[\"test-duplicated\"]}" --endpoint-url http://localhost:4566
  • aws events put-rule --name rule-duplicated2 --event-pattern "{\"source\": [\"test\"], \"detail-type\":[\"test-duplicated\"]}" --endpoint-url http://localhost:4566
  1. Create the rule targets
  • aws events put-targets --rule rule-duplicated1 --targets "Id"="test1","Arn"="arn:aws:sqs:eu-west-1:000000000000:test-queue " --endpoint-url http://localhost:4566
  • aws events put-targets --rule rule-duplicated1 --targets "Id"="test2","Arn"="arn:aws:sqs:eu-west-1:000000000000:test-queue " --endpoint-url http://localhost:4566
  • aws events put-targets --rule rule-duplicated2 --targets "Id"="test3","Arn"="arn:aws:sqs:eu-west-1:000000000000:test-queue " --endpoint-url http://localhost:4566
    aws events put-targets --rule rule-duplicated2 --targets "Id"="test4","Arn"="arn:aws:sqs:eu-west-1:000000000000:test-queue " --endpoint-url http://localhost:4566
  1. Check created rules and targets to ensure created properly
  • aws events list-rules --endpoint-url http://localhost:4566
  • aws events list-targets-by-rule --rule rule-duplicated1 --endpoint-url http://localhost:4566
  • aws events list-targets-by-rule --rule rule-duplicated2 --endpoint-url http://localhost:4566
  1. Put events with example payload to be matched
  • aws events put-events --entries file://~/putevents.json --endpoint-url http://localhost:4566
  • with input file putevents.json payload:
[
  {
    "Source": "test",
    "Detail": "{\"test\": 123}",
    "DetailType": "test-duplicated"
  }
]
  • example of response:
{
    "FailedEntryCount": 0,
    "Entries": [
        {
            "EventId": "f5e5f2d3-3f34-4cc0-a37c-7d61d4daef5f"
        },
        {
            "EventId": "f5e5f2d3-3f34-4cc0-a37c-7d61d4daef5f"
        },
        {
            "EventId": "f5e5f2d3-3f34-4cc0-a37c-7d61d4daef5f"
        },
        {
            "EventId": "f5e5f2d3-3f34-4cc0-a37c-7d61d4daef5f"
        }
    ]
}

Environment

- OS: Mac 14.5
- LocalStack:
  LocalStack version: 3.7.2
  LocalStack Docker image sha: sha256:e773b3a4cf1167c3ffa17ed1dc22ceb3bfbc664c7227b51a02a9fee7a33135b9
  LocalStack build date: 2024-09-06
  LocalStack build git hash: a607fed91

Anything else?

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions