aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

Event Rule with Target creates circular reference.

Open evildani opened this issue 7 years ago • 4 comments

Describe the bug When creating a event rule, with pattern and target, the target's source arn is generated with rule's arn. Thus creating a circular reference.

To Reproduce Create a function, create an event, create a pattern and register both to the event. The resulting cloudformation has the circular reference. The target's arn can't be overwritten to use the correct arn. Synth result:

    Type: AWS::Events::Rule
    Properties:
      EventPattern:
        detail:
          - '{"State":["running","shutting-down","stopped"]}'
        detail-type:
          - EC2 Instance State-change Notification
        id:
          - eventPatternForLambda
        region:
          - us-west-1
        source:
          - aws.ec2
      State: ENABLED
      Targets:
        - Arn:
            Fn::GetAtt:
              - MyLambdaCfnEventRuleF85763DB
              - Arn
          Id: StackLambdaDDNSMyLambdaCfnEventRule7AA3E130
MyLambdaCfnEventRuleF85763DB:
    Type: AWS::Events::Rule
    Properties:
      EventPattern:
        detail:
          - '{"State":["running","shutting-down","stopped"]}'
        detail-type:
          - EC2 Instance State-change Notification
        id:
          - eventPatternForLambda
        region:
          - us-west-1
        source:
          - aws.ec2
      State: ENABLED
      Targets:
        - Arn:
            Fn::GetAtt:
              - MyLambdaCfnEventRuleF85763DB
              - Arn
          Id: StackLambdaDDNSMyLambdaCfnEventRule7AA3E130

Expected behavior

The Arn on the Target should be the ARN of the function defined in the code. Version: 0.29.0

evildani avatar Apr 29 '19 16:04 evildani

The bug comes from line 121 in rule.ts in aws-events module. const targetProps = target.asEventRuleTarget(this.ruleArn, this.node.uniqueId);

evildani avatar Apr 29 '19 16:04 evildani

As a side thing - you'll find the synth output will display properly if you use a ``` instead of `

As it stands, it's not really easy to parse when trying to understand the bug.

leepa avatar Apr 29 '19 17:04 leepa

Thanks 👍

leepa avatar Apr 29 '19 20:04 leepa

I don't think this is still relevant.

Closing, please reopen if I am wrong.

rix0rrr avatar Jun 26 '19 12:06 rix0rrr