Skip to content

Commit

Permalink
Merge pull request #3 from vendrinc/lora/custom-schedule-and-default
Browse files Browse the repository at this point in the history
feat: allow custom schedule for event rule, default is now 1 day
  • Loading branch information
lora-reames authored Dec 28, 2023
2 parents 4886e3e + dc7d72f commit 0287f70
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 19 deletions.
17 changes: 16 additions & 1 deletion API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { CallAwsService } from "aws-cdk-lib/aws-stepfunctions-tasks";
import { Construct } from "constructs";

export interface AccountClosureStepFunctionProps {
/** Arn of privledged role to be assumed by the stepfunction when closing accounts */
readonly privilegedRoleArn: string; // TODO provide example role for repo with all required permissions
/** Custom schedule for the event rule @default 1 day */
readonly schedule?: Schedule;
}
export class AccountClosureStepFunction extends Construct {
constructor(
Expand Down Expand Up @@ -153,7 +156,7 @@ export class AccountClosureStepFunction extends Construct {
definitionBody: DefinitionBody.fromChainable(definition),
},
eventRuleProps: {
schedule: Schedule.rate(Duration.hours(1)),
schedule: props.schedule ?? Schedule.rate(Duration.days(1)),
},
});
}
Expand Down
57 changes: 40 additions & 17 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
import * as cdk from "aws-cdk-lib";
import { Stack } from "aws-cdk-lib";
import { Stack, Duration, App } from "aws-cdk-lib";
import { Template } from "aws-cdk-lib/assertions";
import { Schedule } from "aws-cdk-lib/aws-events";
import { Construct } from "constructs";
import { AccountClosureStepFunction } from "../src/index";

describe("Account Closure Construct", () => {
const app = new cdk.App();
it("should create step function and event rule", async () => {
const app = new App();
class TestStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
new AccountClosureStepFunction(
this,
"AccountClosureStepFunctionConstruct",
{
privilegedRoleArn: "arn:aws:iam::123456789012:role/PrivilegedRole",
}
);
}
}
const testStack = new TestStack(app, "TestStack");
const template = Template.fromStack(testStack);

template.hasResource("AWS::StepFunctions::StateMachine", {});
template.hasResourceProperties("AWS::Events::Rule", {
ScheduleExpression: "rate(1 day)",
});
});

class TestStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
new AccountClosureStepFunction(
this,
"AccountClosureStepFunctionConstruct",
{
privilegedRoleArn: "arn:aws:iam::123456789012:role/PrivilegedRole",
}
);
it("should allow customization of schedule for event rule", async () => {
const app = new App();
class TestStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
new AccountClosureStepFunction(
this,
"AccountClosureStepFunctionConstruct",
{
privilegedRoleArn: "arn:aws:iam::123456789012:role/PrivilegedRole",
schedule: Schedule.rate(Duration.hours(1)),
}
);
}
}
}
const testStack = new TestStack(app, "TestStack");
const template = Template.fromStack(testStack);
const testStack = new TestStack(app, "TestStack");
const template = Template.fromStack(testStack);

it("should create step function and event rule", async () => {
template.hasResource("AWS::StepFunctions::StateMachine", {});
template.hasResourceProperties("AWS::Events::Rule", {
ScheduleExpression: "rate(1 hour)",
Expand Down

0 comments on commit 0287f70

Please sign in to comment.