Skip to content

(aws-ecr): ECR EventBridge rule has incorrect event pattern #29225

@Brads3290

Description

@Brads3290

Describe the bug

Using the CDK, creating an EventBridge rule on an ECR repository creates a rule with the following event pattern:

{
  "resources": ["arn:aws:ecr:ap-southeast-2:<account-id>:repository/my-repository-name"],
  "source": ["aws.ecr"]
}

However when ECR sends the event, "resources" is empty, so the rule never matches (example from https://docs.aws.amazon.com/AmazonECR/latest/userguide/ecr-eventbridge.html#ecr-eventbridge-bus):

{
    "version": "0",
    "id": "13cde686-328b-6117-af20-0e5566167482",
    "detail-type": "ECR Image Action",
    "source": "aws.ecr",
    "account": "123456789012",
    "time": "2019-11-16T01:54:34Z",
    "region": "us-west-2",
    "resources": [], // <--- empty, rule fails
    "detail": {
        "result": "SUCCESS",
        "repository-name": "my-repository-name",
        "image-digest": "sha256:7f5b2640fe6fb4f46592dfd3410c4a79dac4f89e4782432e0378abcd1234",
        "action-type": "PUSH",
        "image-tag": "latest"
    }
}

Expected Behavior

Use the detail.repository-name field as a filter instead of resources:

{
  "detail": {
    "repository-name": ["my-repository-name"]
  },
  "source": ["aws.ecr"]
}

Current Behavior

Uses resources as a filter, which is empty in the real event

Reproduction Steps

var ecrRepo = new EcrRepository(this, "CiTestEcrRepository", new EcrRepositoryProps());
ecrRepo.OnEvent("EcrRepoEventRule", new OnEventOptions() {
    Target = new LambdaFunction(myLambdaHandler),
});

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.127.0 (build 6c90efc)

Framework Version

.NET 8

Node.js Version

v18.16.1

OS

MacOS

Language

.NET

Language Version

.NET 8

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ecrRelated to Amazon Elastic Container RegistrybugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions