Repository: serverless/serverless (JavaScript)

Issue:
EventBridge Pattern validation does not allow more advanced patterns
### Are you certain it's a bug?

- [X] Yes, it looks like a bug

### Is the issue caused by a plugin?

- [X] It is not a plugin issue

### Are you using the latest v3 release?

- [X] Yes, I'm using the latest v3 release

### Is there an existing issue for this?

- [X] I have searched existing issues, it hasn't been reported yet

### Issue description

Using this event pattern:

```
myFunction:
  # ...
  events:
    - eventBridge:
        pattern:
          "$or":
            - source:
                - aws.ecs
              detail-type:
                - ECS Service Action
                - ECS Task State Change
                - ECS Container Instance State Change
                - ECS Deployment State Change
            
            - source:
                - aws.rds
              detail-type:
                - RDS DB Cluster Event
                - RDS DB Instance Event

            - source:
                - aws.ec2
              detail-type:
                - EC2 Spot Instance Interruption Warning
```

Causes this error to be thrown:

```Warning: Invalid configuration encountered
  at 'functions.myFunction.events.0.eventBridge.pattern': unrecognized property '$or'
```

If I ignore this warning, everything works fine. This is a perfectly valid event pattern

### Service configuration (serverless.yml) content

```yaml
Relevant section from my `functions` block


myFunction:
  # ...
  events:
    - eventBridge:
        pattern:
          "$or":
            - source:
                - aws.ecs
              detail-type:
                - ECS Service Action
                - ECS Task State Change
                - ECS Container Instance State Change
                - ECS Deployment State Change
            
            - source:
                - aws.rds
              detail-type:
                - RDS DB Cluster Event
                - RDS DB Instance Event

            - source:
                - aws.ec2
              detail-type:
                - EC2 Spot Instance Interruption Warning
```


### Command name and used flags

serverless package

### Command output

```shell
Warning: Invalid configuration encountered
  at 'functions.myFunction.events.0.eventBridge.pattern': unrecognized property '$or'

Learn more about configuration validation here: http://slss.io/configuration-validation
```


### Environment information

```shell
Framework Core: 3.30.1 (local)
Plugin: 6.2.3
SDK: 4.3.2
```



Discussion:
@webdestroya this looks as simply bug in our validation schema. PR with a fix is welcome!
@medikoo PR Submitted!



Patch:
diff --git a/lib/plugins/aws/package/compile/events/event-bridge/index.js b/lib/plugins/aws/package/compile/events/event-bridge/index.js
index 4192a9b3643..77bda57dfc9 100644
--- a/lib/plugins/aws/package/compile/events/event-bridge/index.js
+++ b/lib/plugins/aws/package/compile/events/event-bridge/index.js
@@ -95,6 +95,7 @@ class AwsCompileEventBridgeEvents {
             'region': {},
             'resources': {},
             'detail': {},
+            '$or': { type: 'array' },
           },
           additionalProperties: false,
         },


Test patch:
diff --git a/test/unit/lib/plugins/aws/package/compile/events/event-bridge/index.test.js b/test/unit/lib/plugins/aws/package/compile/events/event-bridge/index.test.js
index 351c83ec652..73b0f642fc9 100644
--- a/test/unit/lib/plugins/aws/package/compile/events/event-bridge/index.test.js
+++ b/test/unit/lib/plugins/aws/package/compile/events/event-bridge/index.test.js
@@ -152,6 +152,26 @@ const serverlessConfigurationExtension = {
         },
       ],
     },
+    orPattern: {
+      handler: 'index.handler',
+      events: [
+        {
+          eventBridge: {
+            eventBus: 'arn:aws:events:us-east-1:12345:event-bus/default',
+            pattern: {
+              $or: [
+                {
+                  detail: {
+                    eventSource: ['saas.external'],
+                  },
+                },
+                { source: ['aws.cloudformation'] },
+              ],
+            },
+          },
+        },
+      ],
+    },
   },
 };
 
@@ -273,6 +293,16 @@ describe('EventBridgeEvents', () => {
       expect(eventTime).be.eq('$.time');
     });
 
+    it('should support $or pattern in event pattern', () => {
+      const eventBridgeConfig = getEventBridgeConfigById('orPattern');
+      expect(eventBridgeConfig.Pattern.$or[0]).to.deep.equal({
+        detail: {
+          eventSource: ['saas.external'],
+        },
+      });
+      expect(eventBridgeConfig.Pattern.$or[1]).to.deep.equal({ source: ['aws.cloudformation'] });
+    });
+
     it('should register created and delete event bus permissions for non default event bus', () => {
       const roleId = naming.getCustomResourcesRoleLogicalId('customSaas', '12345');
       const [firstStatement] = cfResources[roleId].Properties.Policies[0].PolicyDocument.Statement;