- Newest
- Most votes
- Most comments
Based on your description, you're encountering a common issue with EventBridge rules targeting CloudWatch Logs in CloudFormation templates. Let me clarify how this should work:
When CloudWatch Logs is the target of an EventBridge rule, you don't need to specify a RoleArn in the target configuration. Instead, CloudWatch Logs requires a resource-based policy that enables EventBridge to write to it. This is why you received the error stating "RoleArn is not supported for target" when you included it.
For your second error about missing EventPattern, this could be due to a few issues:
- YAML indentation problems - EventPattern needs to be properly indented under Properties
- A potential issue with how the template is being processed
Here's the correct approach:
- Remove the RoleArn from the target configuration
- Create a resource-based policy for CloudWatch Logs
- Ensure your EventPattern is correctly formatted
Your EventBridge rule should look like this:
RetsEventBusLoggingRule: Type: AWS::Events::Rule Properties: EventBusName: !Ref RetsEventBus EventPattern: source: - "com.cth.rets.delta" Targets: - Arn: !GetAtt RetsEventBusLogGroup.Arn Id: "RetsEventBusLogGroupTarget"
And add a resource policy:
LogsResourcePolicy: Type: AWS::Logs::ResourcePolicy Properties: PolicyName: EventBridgeToCloudWatchLogs PolicyDocument: !Sub | { "Version": "2012-10-17", "Statement": [ { "Sid": "EventBridgeToCloudWatchLogs", "Effect": "Allow", "Principal": {"Service": "events.amazonaws.com"}, "Action": ["logs:PutLogEvents","logs:CreateLogStream"], "Resource": "${RetsEventBusLogGroup.Arn}" } ] }
If you're still encountering the "Parameter(s) EventPattern or ScheduleExpression must be specified" error despite having a valid EventPattern, try these troubleshooting steps:
- Validate your CloudFormation template using the AWS CLI command
aws cloudformation validate-template - Try simplifying your template to just the EventBridge rule and its dependencies to isolate the issue
- Check if there are any transform operations in your template that might be affecting how EventPattern is processed
The resource-based policy approach is the correct way to handle permissions for EventBridge to write to CloudWatch Logs, not an IAM role attached to the target.
Sources
EventBridge Rule Target ID | AWS re:Post
How does EventBridge Pipes have permissions to log to CloudWatch? | AWS re:Post
Relevant content
asked 2 years ago
