Skip to content

Commit

Permalink
When eventbridge destroy helper is called also remove the rule
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejscott committed Aug 16, 2021
1 parent 9553cf0 commit 44a582e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"endOfLine": "auto"
}
15 changes: 12 additions & 3 deletions src/helpers/eventBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default class EventBridge {
async init(eventBridgeName) {
this.eventBridgeClient = new AWSClient.EventBridge();
this.eventBridgeName = eventBridgeName;
this.ruleName = `test-${eventBridgeName}-rule`;

const keepArg = process.argv.filter((x) => x.startsWith("--keep="))[0];
this.keep = keepArg ? keepArg.split("=")[1] : false;
this.sqsClient = new AWSClient.SQS();
Expand All @@ -27,10 +29,9 @@ export default class EventBridge {
account: [`${accountId}`],
};

const ruleName = `test-${eventBridgeName}-rule`;
await this.eventBridgeClient
.putRule({
Name: ruleName,
Name: this.ruleName,
EventBusName: eventBridgeName,
EventPattern: JSON.stringify(pattern),
State: "ENABLED",
Expand All @@ -40,7 +41,7 @@ export default class EventBridge {
await this.eventBridgeClient
.putTargets({
EventBusName: eventBridgeName,
Rule: ruleName,
Rule: this.ruleName,
Targets: [
{
Arn: sqsArn,
Expand Down Expand Up @@ -140,6 +141,14 @@ export default class EventBridge {
QueueUrl: this.QueueUrl,
})
.promise();

await this.eventBridgeClient
.deleteRule({
Name: this.ruleName,
EventBusName: this.eventBridgeName,
Force: true,
})
.promise();
} else {
await this.clear();
}
Expand Down

0 comments on commit 44a582e

Please sign in to comment.