Peter
Peter

Reputation: 2394

Issue with EventBridge rule for aws.events

I want to send to CloudWatch logs ALL the events sent to a custom event bus.

I created the custom event bus: my-event-bus

I created the CloudWatch log group

I created the event bus policy so everyone within my account can put an event into my-event-bus

I created a rule for that custom bus

This is the rule:

  MyRuleForBus:
    Type: AWS::Events::Rule
    Properties:
      Description: Testing rule
      EventBusName: 
      Name: testing-rule-for-my-event-bus
      EventPattern:
        source:
          - aws.events
      State: ENABLED
      Targets:
        - Arn: arn:aws:logs:us-east-1:MY_ACCOUNT_ID:log-group:my-event-bus-log-group
          Id: 'my-bus'

When I try to put an event aws events put-events --entries file://put-events.json

I receive the following error

{
    "FailedEntryCount": 1,
    "Entries": [
        {
            "ErrorCode": "NotAuthorizedForSourceException",
            "ErrorMessage": "Not authorized for the source."
        }
    ]
}

This is the content of put-events.json

[
    {
      "Source": "aws.events",
      "EventBusName": "my-event-bus",
      "Detail": "{ \"key1\": \"value3\", \"key2\": \"value4\" }",
      "Resources": [
        "resource1",
        "resource2"
      ],
      "DetailType": "myDetailType"
     }
  ]

But, if I change the source to other, for example, 'hello', in both, the rule and the event it works.

What am I doing wrong? I want to make it work with aws.events so all the events sent to this bus end in CloudWatch (target)

Upvotes: 17

Views: 14607

Answers (1)

Marcin
Marcin

Reputation: 238051

aws.events belongs to AWS, not to you, thus you can't define it as source of your events. Only AWS can do it.

You need to use your own custom name for the source of your events, e.g. myapp.events.

Upvotes: 35

Related Questions