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

aws_ecr: repository.on_event() creates an event that never fires #29815

Closed
mrudelle opened this issue Apr 12, 2024 · 3 comments
Closed

aws_ecr: repository.on_event() creates an event that never fires #29815

mrudelle opened this issue Apr 12, 2024 · 3 comments
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@mrudelle
Copy link

Describe the bug

The event created by the method .on_event() of an ecr.Repository does not fire. And I suspect this is because the event behavior filters for resources which is not specified in the ecr event.

Expected Behavior

When a new image is pushed to the repository, an event should fire.

Current Behavior

No event is fired.

Reproduction Steps

We are creating the rule like this:

repository_name="my-repo"
container_repository = ecr.Repository(
    self, 'Repository',
    repository_name=repository_name,
)

notify_fn = aws_lambda.Function(
    self, 'NotifyFn',
    runtime=aws_lambda.Runtime.PYTHON_3_12,
    code=aws_lambda.Code.from_asset('lambdas/ecr-notify'),
    handler='handler.lambda_handler',
)

rule = container_repository.on_event(
    'RepositoryNewReleaseEvent',
    target=targets.LambdaFunction(notify_fn)
)

rule.add_event_pattern(
    detail_type=["ECR Image Action"],
    detail={
        "action-type": ["PUSH"],
        "result": ["SUCCESS"],
        "repository-name": [container_repository.repository_name],
    }
)

In the console, that creates the following event pattern:

{
  "detail-type": ["ECR Image Action"],
  "resources": ["arn:aws:ecr:eu-central-1:XXXXXXXX:repository/XXXXXXX"],
  "source": ["aws.ecr"],
  "detail": {
    "result": ["SUCCESS"],
    "repository-name": ["XXXXXXX"],
    "action-type": ["PUSH"]
  }
}

And the event is never fired. But if instead I create the event like this:

repository_name="my-repo"
container_repository = ecr.Repository(
    self, 'Repository',
    repository_name=repository_name,
)

notify_fn = aws_lambda.Function(
    self, 'NotifyFn',
    runtime=aws_lambda.Runtime.PYTHON_3_12,
    code=aws_lambda.Code.from_asset('lambdas/ecr-notify'),
    handler='handler.lambda_handler',
)

rule = events.Rule(
    self, 'NotifyRule',
    targets=[targets.LambdaFunction(notify_fn)],
    event_pattern=events.EventPattern(
        source=["aws.ecr"],
        detail_type=["ECR Image Action"],
        detail={
            'action-type': ["PUSH"],
            'result': ["SUCCESS"],
            'repository-name': [container_repository.repository_name],
        }
    )
)

The following event pattern is created:

{
  "detail-type": ["ECR Image Action"],
  "detail": {
    "result": ["SUCCESS"],
    "repository-name": ["XXXXXXX"],
    "action-type": ["PUSH"]
  },
  "source": ["aws.ecr"]
}

And events fire as expected

Possible Solution

The event that is sent to the lambda has an empty array for resources. That could be why the event is not fired, if it tries to match for this property.

Additional Information/Context

No response

CDK CLI Version

2.131.0 (build 92b912d)

Framework Version

aws-cdk-lib==2.131.0

Node.js Version

v18.19.0

OS

MacOS

Language

Python

Language Version

Python 3.10.10

Other information

No response

@mrudelle mrudelle added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecr Related to Amazon Elastic Container Registry label Apr 12, 2024
@mrudelle
Copy link
Author

Actually, this issue was already reported here #29225

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants