Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f9a375f

Browse files
authoredOct 23, 2019
Merge pull request #270 from PhileasSystems/master
feat: support EventBusName for custom Cloudwatch event bus
2 parents 4af0434 + 7236c61 commit f9a375f

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed
 

‎README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ This is the Serverless Framework plugin for AWS Step Functions.
4040
- [Specify Input or Inputpath](#specify-input-or-inputpath)
4141
- [Specifying a Description](#specifying-a-description)
4242
- [Specifying a Name](#specifying-a-name)
43+
- [Specifying a custom CloudWatch EventBus](#specifying-a-custom-cloudwatch-eventbus)
4344
- [Tags](#tags)
4445
- [Commands](#commands)
4546
- [deploy](#deploy)
@@ -933,6 +934,29 @@ stepFunctions:
933934
...
934935
```
935936

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

938962
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 +1383,4 @@ stepFunctions:
13591383
13601384
plugins:
13611385
- serverless-step-functions
1362-
```
1386+
```

‎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)
Please sign in to comment.