aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap
AWS::Events::Rule RoleArn Property not used for target invoke?
- Dominant language
- No language data
- Stars
- 1.1k
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
### Name of the resource
AWS::Events::Rule
### Resource Name
AWS::Events::Rule
### Issue Description
## AWS::Events::Rule RoleArn Property
### Background
I am opening up this issue off the back of a pull request opened within the [aws-cloudformation-user-guide](https://github.com/awsdocs/aws-cloudformation-user-guide) repo. The pull request is ["Change AWS::Events::Rule Target RoleArn property to 'Conditional' #1178"](https://github.com/awsdocs/aws-cloudformation-user-guide/pull/1178).
The below [comment](https://github.com/awsdocs/aws-cloudformation-user-guide/pull/1178#issuecomment-1067031212) was main by maintainer [Patrick Rachford](https://github.com/rachfop):
> This does look like an issue – to report issues with the resources and properties defined in the Resource Spec – you can open an issue here: https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues
>
> That will allow the Event and CloudFormation devs to take a look at the underlining issue. I'll keep this doc PR open for kinclay to approve/merge/close. Thanks again for the deep dive.
### Problem Overview
The docs define [RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-rolearn) as
> The Amazon Resource Name (ARN) of the role that is used for target invocation.
Which gives me the impression that the defined RoleArn will be used to invoke the respective targets (defined under the _Targets_ property).
So lets define a role called, _Role_X_:
Assuming that _Role_X_ has the required policies assigned, is it safe for us to say that _Role_X_ will be used to invoke the respective target(s)? In other words, assuming correct permissions, if we do not define a target specific role (i.e. [events-rule-target-rolearn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-rolearn)) then _Role_X_ (i.e. the [events-rule-rolearn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-rolearn)) will be successfully used for invocation of targets.
With that being said, I've observed that when defining the [events-rule-rolearn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-rolearn) CloudFormation throws the following error:
> RoleArn is required for target arn:aws:codebuild:af-south-1:00000000:project/codebuild-project-1.
> (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException;
> Request ID: XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX; Proxy: null)
As mentioned in the pull request (["Change AWS::Events::Rule Target RoleArn property to 'Conditional' #1178"](https://github.com/awsdocs/aws-cloudformation-user-guide/pull/1178)). The error was only resolved after setting the target specific RoleArn, [events-rule-target-rolearn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-rolearn), under the Target definition. Defining the [events-rule-rolearn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-rolearn) seemed to have no effect on the error. It is also important to note that in my test case, I am only defining one target for invocation. For the full explanation on how I fixed the error please see my pull request [comment](https://github.com/awsdocs/aws-cloudformation-user-guide/pull/1178#issuecomment-1065010610).
### Expected Behavior
When I define the [events-rule-rolearn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-rolearn) RoleArn, the specified Role should be used by the Events Resource to invoke the defined target(s).
In the case below, the _MyEventBridgeEventRuleTargetRole_ should be used by the _MyEventBridgeEventRule_ resource to invoke the defined CodeBuild target.
```
MyEventBridgeEventRule:
Type: AWS::Events::Rule
Properties:
Name: MyEventBridgeEventRule
Description: EventBridge Event Rule Description
RoleArn: arn:aws:iam::00000000:role/MyEventBridgeEventRuleTargetRole
Targets:
- Arn: arn:aws:codebuild:af-south-1:000000000:project/c_build
Id: unique-target-id-to-invoke
EventPattern: ...
.
.
.
```
### Observed Behavior
The CloudFormation stack creation process throws the following error:
> RoleArn is required for target arn:aws:codebuild:af-south-1:00000000:project/codebuild-project-1.
> (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException;
> Request ID: XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX; Proxy: null)
### Test Cases
Below is a CloudFormation template which yields the above error.
```
---
AWSTemplateFormatVersion: 2010-09-09
Description: |
Cloudformation EventBridge Event Rule Error.
Error:
RoleArn is required for target arn:aws:codebuild:af-south-1:00000000:project/codebuild-project-1.
(Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException;
Request ID: XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX; Proxy: null)
Assumptions:
- There exists a CodeBuild Project
- There exists an EventBridge Event Role with the permission to run codebuild.
- The role should:
- Allow for events.amazonaws.com to assume the role
- Allow events.amazonaws.com to invoke and run codebuild
Parameters:
#CodeBuild
CodeBuildProjectName:
Default: aws-cb-event-trgt
Description: The AWS CodeBuild Event Target Project Name.
Type: String
MinLength: "1"
CodeBuildProjectArn:
Default: arn:aws:codebuild:af-south-1:00000000:project/codebuild-project-1
Description: The AWS CodeBuild Event Target Project ARN.
Type: String
MinLength: "1"
#EventBridgeEvent
EventBridgeEventRoleArn:
Default: arn:aws:iam::00000000:role/CWEventBridgeCodeBuildTargetRole
Description: The AWS CloudWatch (EventBridge) Event RoleArn.
Type: String
MinLength: "1"
Resources:
MyEventBridgeEventRule:
Type: AWS::Events::Rule
Properties:
Name: MyEventBridgeEventRule
Description: Cloudwatch (EventBridge) Event Rule for triggering CodeBuild based on schedule.
RoleArn: !Ref EventBridgeEventRoleArn
ScheduleExpression: "rate(5 minutes)"
State: ENABLED
Targets:
- Arn: !Ref CodeBuildProjectArn
Id: !Sub "trgt-${CodeBuildProjectName}"
```
### Other Details
For background, please see pull request ["Change AWS::Events::Rule Target RoleArn property to 'Conditional' #1178"](https://github.com/awsdocs/aws-cloudformation-user-guide/pull/1178) within the [aws-cloudformation-user-guide](https://github.com/awsdocs/aws-cloudformation-user-guide) repo.
Contributor guide
Research direction
Start with the supplied CloudFormation template for AWS::Events::Rule and reproduce the failure using a CodeBuild target. Compare the rule-level RoleArn with the target-specific RoleArn and review the linked EventBridge and CloudFormation documentation and pull request. Done means establishing whether the rule-level role should authorize target invocation and documenting or correcting the resulting resource behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100