如何在无服务器/cloudformation 中为合作伙伴事件总线创建事件规则

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

我正在尝试为合作伙伴事件总线创建事件规则,即 arn:aws:events:{region}:{accountId}:event-bus/aws.partner/appflow/salesforce.com/{accountId} 以将所有事件发送到无服务器中的 SQS 队列,但运气不佳,我一直遇到此错误:

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).

对于上下文,合作伙伴事件总线名称是在创建 appflow 时自动生成的,因此无法避免名称中的 aws

我可以通过 AWS 控制台创建它,即 arn:aws:events:{region}:{accountId}:rule/aws.partner/appflow/salesforce.com/{accountId}/myPartnerEventRule1,但真的很难通过无服务器/cloudformation 创建它。

这里是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}'
                       

尝试了一些没有用的东西:

有什么想法吗?

所以这也是我偶然发现的 AWS Cloudformation 中的一个错误。 我联系了 AWS Support 并获得了一些很大的帮助(案例 ID 9092652141)。

这是他们对这个问题的看法

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.

但是,在他们自己的环境中重现该问题后,他们还提供了一个临时解决方法。

不要使用 Arn 或复制粘贴事件总线的名称,而是添加对事件总线名称的引用。我昨天试了这个方法,成功创建了事件总线和规则。

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