Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions API.md

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

27 changes: 27 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Stack } from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as logs from 'aws-cdk-lib/aws-logs';
import * as scheduler from 'aws-cdk-lib/aws-scheduler';
import * as sns from 'aws-cdk-lib/aws-sns';
import { LogLevel as EC2InstanceRunningScheduleStackMachineLogLevel } from 'aws-cdk-lib/aws-stepfunctions';
import { Construct } from 'constructs';
import { RunningControlStateMachine } from './resources/running-control-state-machine';

export {
EC2InstanceRunningScheduleStackMachineLogLevel,
};

export interface TargetResource {
readonly tagKey: string;
readonly tagValues: string[];
Expand All @@ -22,11 +28,16 @@ export interface Notifications {
// readonly slack?: Slack;
}

export interface LogOption {
readonly machineLogLevel?: EC2InstanceRunningScheduleStackMachineLogLevel;
}

export interface EC2InstanceRunningScheduleStackProps {
readonly targetResource: TargetResource;
readonly stopSchedule?: Schedule;
readonly startSchedule?: Schedule;
readonly notifications?: Notifications;
readonly logOption?: LogOption;
}

export class EC2InstanceRunningScheduleStack extends Stack {
Expand All @@ -51,6 +62,22 @@ export class EC2InstanceRunningScheduleStack extends Stack {
const machine = new RunningControlStateMachine(this, 'StateMachine', {
stateMachineName: undefined,
notificationTopic: topic,
logs: (() => {
if (props.logOption?.machineLogLevel) {
return {
destination: new logs.LogGroup(this, 'StateMachineLogGroup', {
logGroupName: (() => {
// if (names.stateMachineName) {
// return `/aws/states/${names.stateMachineName}`;
// }
return undefined;
})(),
}),
level: props.logOption.machineLogLevel,
};
}
return undefined;
})(),
});

// 👇 EventBridge Scheduler IAM Role
Expand Down
37 changes: 37 additions & 0 deletions test/__snapshots__/stack.specific.test.ts.snap

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

5 changes: 4 additions & 1 deletion test/stack.specific.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { EC2InstanceRunningScheduleStack } from '../src';
import { EC2InstanceRunningScheduleStack, EC2InstanceRunningScheduleStackMachineLogLevel } from '../src';

describe('Ec2InstanceRunningScheduleStack specific Testing', () => {

Expand Down Expand Up @@ -29,6 +29,9 @@ describe('Ec2InstanceRunningScheduleStack specific Testing', () => {
'bar@example.net',
],
},
logOption: {
machineLogLevel: EC2InstanceRunningScheduleStackMachineLogLevel.ALL,
},
});

const template = Template.fromStack(stack);
Expand Down