Skip to content

Commit cdc9a8c

Browse files
committed
feat: support EventBusName for custom Cloudwatch event bus
1 parent 4af0434 commit cdc9a8c

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,29 @@ stepFunctions:
933933
...
934934
```
935935

936+
#### Specifying a custom CloudWatch EventBus
937+
938+
You can choose which CloudWatch Event bus to listen to:
939+
940+
```yml
941+
stepFunctions:
942+
stateMachines:
943+
cloudwatchEvent:
944+
events:
945+
- cloudwatchEvent:
946+
eventBusName: 'my-custom-event-bus'
947+
event:
948+
source:
949+
- "my.custom.source"
950+
detail-type:
951+
- "My Event Type"
952+
detail:
953+
state:
954+
- pending
955+
definition:
956+
...
957+
```
958+
936959
## Tags
937960

938961
You can specify tags on each state machine. Additionally any global tags (specified under `provider` section in your `serverless.yml`) would be merged in as well.
@@ -1359,4 +1382,4 @@ stepFunctions:
13591382
13601383
plugins:
13611384
- serverless-step-functions
1362-
```
1385+
```

lib/deploy/events/cloudWatchEvent/compileCloudWatchEventEvents.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
let InputPath;
2020
let Description;
2121
let Name;
22+
let EventBusName;
2223

2324
if (typeof event.cloudwatchEvent === 'object') {
2425
if (!event.cloudwatchEvent.event) {
@@ -39,6 +40,7 @@ module.exports = {
3940
InputPath = event.cloudwatchEvent.inputPath;
4041
Description = event.cloudwatchEvent.description;
4142
Name = event.cloudwatchEvent.name;
43+
EventBusName = event.cloudwatchEvent.eventBusName;
4244

4345
if (Input && InputPath) {
4446
const errorMessage = [
@@ -78,6 +80,7 @@ module.exports = {
7880
{
7981
"Type": "AWS::Events::Rule",
8082
"Properties": {
83+
${EventBusName ? `"EventBusName": "${EventBusName}",` : ''}
8184
"EventPattern": ${EventPattern.replace(/\\n|\\r/g, '')},
8285
"State": "${State}",
8386
${Description ? `"Description": "${Description}",` : ''}

lib/deploy/events/cloudWatchEvent/compileCloudWatchEventEvents.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,36 @@ describe('awsCompileCloudWatchEventEvents', () => {
262262
.Properties.Name).to.equal('test-event-name');
263263
});
264264

265+
it('should respect eventBusName variable', () => {
266+
serverlessStepFunctions.serverless.service.stepFunctions = {
267+
stateMachines: {
268+
first: {
269+
events: [
270+
{
271+
cloudwatchEvent: {
272+
event: {
273+
source: ['aws.ec2'],
274+
'detail-type': ['EC2 Instance State-change Notification'],
275+
detail: { state: ['pending'] },
276+
},
277+
enabled: false,
278+
input: '{"key":"value"}',
279+
name: 'test-event-name',
280+
eventBusName: 'custom-event-bus',
281+
},
282+
},
283+
],
284+
},
285+
},
286+
};
287+
288+
serverlessStepFunctions.compileCloudWatchEventEvents();
289+
290+
expect(serverlessStepFunctions.serverless.service
291+
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleCloudWatchEvent1
292+
.Properties.EventBusName).to.equal('custom-event-bus');
293+
});
294+
265295
it('should respect input variable as an object', () => {
266296
serverlessStepFunctions.serverless.service.stepFunctions = {
267297
stateMachines: {

0 commit comments

Comments
 (0)