aws / aws/aws-cdk

(aws-cdk-lib.pipelines): (EventBridge rule fails in the cross-account configuration due to a lack of RoleArn property)

Open
#24,843 1 comment 2 reactions 0 assignees View on GitHub
@aws-cdk/pipelines bug effort/medium p1
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

I'm trying to deploy the CDK Pipeline construct in the cross-account configuration, as in the picture below. Deployment of the `AWS::Events::Rule` resource fails due to a lack of the `RoleArn` property. It looks like it's related to the [change provided by the AWS](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cross-account.html).
> EventBridge now requires all new cross account event bus targets to add IAM roles. This only applies to event bus targets created after March 2, 2023.

![Simplified-Architecture](https://github.com/holowieszek/aws-cdk-pipeline-codecommit-cross-account-rolearn-issue/raw/develop/architecture.drawio.png)

### Expected Behavior

The EventRule target should be created with the IAM role attached.

### Current Behavior

The synthesized template does not have the `RoleArn` in the `Targets`.
```
BugReproduceRepositorydevBugReproducePipelinedevPipeline60E290CDdevelopEventRule406D1E8D:
Type: AWS::Events::Rule
Properties:
EventPattern:
source:
- aws.codecommit
resources:
- arn:aws:codecommit:eu-central-1:111111111111:codecommit-repository
detail-type:
- CodeCommit Repository State Change
detail:
event:
- referenceCreated
- referenceUpdated
referenceName:
- develop
State: ENABLED
Targets:
- Arn: arn:aws:events:eu-central-1:222222222222:event-bus/default
Id: Target0
```
As a result, this error occurs:
> RoleArn is required for target arn:aws:events:eu-central-1:222222222222:event-bus/default. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: 564e1b69-13ea-4c53-b411-0b68bae707ac; Proxy: null)

### Reproduction Steps

The repository with the sample that reproduces the bug can be found [here](https://github.com/holowieszek/aws-cdk-pipeline-codecommit-cross-account-rolearn-issue).
It is required to bootstrap CDK with the `bugreproduce` qualifier name (or you can specify your name in the `cdk.json`).
Properties like account ids, regions, and repository name can be configured in the `bin/issue.ts`.

### Possible Solution

It would be perfect to have the ability to attach `RoleArn` to the `AWS::Events::Rule` resource generated by the CDK under the hood. Another solution is to attach `RoleArn` automatically by CDK.
As a temporary solution, it would be good to have some workaround to override resource properties generated by the CDK. Unless there is already a native solution and I suffer from a lack of knowledge. It is also possible.

### Additional Information/Context

[Grant permissions to allow events from other AWS accounts](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cross-account.html).
> EventBridge now requires all new cross account event bus targets to add IAM roles. This only applies to event bus targets created after March 2, 2023.

[AWS::Events::Rule Target CloudFormation documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html)
> If you are setting the event bus of another account as the target, and that account granted permission to your account through an organization instead of directly by the account ID, then you must specify a RoleArn with proper permissions in the Target structure.

Additional note: this deployment works perfectly on another account. I can create EventRule without `RoleArn` being specified. I don't know why.

### CDK CLI Version

2.69

### Framework Version

2.69

### Node.js Version

18.15.0

### OS

Ubuntu 20.04.5 LTS

### Language

Typescript

### Language Version

~4.9.5

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the cross-account reproduction configured in bin/issue.ts and cdk.json, then synthesize the stack and inspect the AWS::Events::Rule target shown in the issue. Compare the generated template with the EventBridge cross-account requirements; done means the target includes the required role information and the deployment succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.