Search code examples
amazon-web-servicesaws-event-bridgeserverless.com

How to create event rule for partner event bus in serverless / cloudformation


I am trying to create an event rule for the partner event bus i.e. arn:aws:events:{region}:{accountId}:event-bus/aws.partner/appflow/salesforce.com/{accountId} to send all events to an SQS queue in serverless but not having much luck, I keep hitting this error:

Serverless Error ----------------------------------------
  An error occurred: SFSubscriptionPartnerEventsRule - EventBus name starting with 'aws.' is not valid. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: ; Proxy: null).

For context, partner event bus names are auto generated when creating appflow so there is no way of avoiding aws in the name.

I can create this via the AWS console i.e. arn:aws:events:{region}:{accountId}:rule/aws.partner/appflow/salesforce.com/{accountId}/myPartnerEventRule1, but really struggling to create it via serverless / cloudformation.

Here is the relevant section of cloudformation:

Type: AWS::Events::Rule
            Properties:
                Description: 'write salesforce subscription event to sqs'
                Name: 'events-${self:custom.deployingStage}-sfsubscriptionevent-sfsubscriptionsqs'
                EventBusName: 
                    Fn::GetAtt:
                        - CustomerPlatformSFPartnerEventBus
                        - Arn
                EventPattern:
                    account:
                        - Ref: 'AWS::AccountId'
                State: ENABLED
                Targets:
                    -   Arn:
                            Fn::GetAtt:
                                - SFSubscriptionToCustomerPlatformQueue
                                - Arn
                        Id: '${self:custom.queue.sfSubscriptionToCustomerPlatformQueue}'
                       

Tried a few things with no avail:

  • updated serverless to the latest version 2.51
  • I do wonder if you create the event rule as part of the appflow definition AWS::AppFlow::Flow but can not find anything in the documentation; maybe im being blind.
  • to 'rule' anything else out if i change EventBusName: value to Fn::ImportValue: 'DefaultEventBusARN-${self:custom.deployingStage}' i.e. a non partner event bus it deploys ok. But I want the rule on the partner event bus.

Any ideas?


Solution

  • So this is a bug in AWS Cloudformation that I stumbled upon as well. I contacted AWS Support and I got some great help (Case ID 9092652141).

    This is what they said regarding the issue

    I would like to extend my sincere apologies for any inconvenience that this issue may have caused you and I would like to inform you that I have reached out to the internal team about this behavior and asked investigate the issue.

    However, they also provided with a temporary workaround after replicating the issue in their own environment.

    Instead of using the Arn or copy-pasting the Name of the Event bus, add the reference to the Event bus name. I tried this method yesterday and successfully created both the event bus and the rule.

    That being said, as for now in order to create the Event Rule, I would request you to pass the name of Event Bus instead of Arn.

    Resources:
      EventBus:
        Type: AWS::Events::EventBus
        Properties:
          EventSourceName: <copy-paste the event source name of the partner here>
          Name: <Same as above>
    
      EventRule:
        Type: AWS::Events::Rule
        Properties:
          Name: <Event rule name>
          EventBusName: !GetAtt EventBus.Name