Skip to content

Commit 7c7e1ba

Browse files
authored
Merge pull request #210 from gammarers/feature/add-machine-logging-option
feat: add machine logging option
2 parents 8121235 + 60cf2e0 commit 7c7e1ba

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

API.md

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { Stack } from 'aws-cdk-lib';
22
import * as iam from 'aws-cdk-lib/aws-iam';
3+
import * as logs from 'aws-cdk-lib/aws-logs';
34
import * as scheduler from 'aws-cdk-lib/aws-scheduler';
45
import * as sns from 'aws-cdk-lib/aws-sns';
6+
import { LogLevel as EC2InstanceRunningScheduleStackMachineLogLevel } from 'aws-cdk-lib/aws-stepfunctions';
57
import { Construct } from 'constructs';
68
import { RunningControlStateMachine } from './resources/running-control-state-machine';
79

10+
export {
11+
EC2InstanceRunningScheduleStackMachineLogLevel,
12+
};
13+
814
export interface TargetResource {
915
readonly tagKey: string;
1016
readonly tagValues: string[];
@@ -22,11 +28,16 @@ export interface Notifications {
2228
// readonly slack?: Slack;
2329
}
2430

31+
export interface LogOption {
32+
readonly machineLogLevel?: EC2InstanceRunningScheduleStackMachineLogLevel;
33+
}
34+
2535
export interface EC2InstanceRunningScheduleStackProps {
2636
readonly targetResource: TargetResource;
2737
readonly stopSchedule?: Schedule;
2838
readonly startSchedule?: Schedule;
2939
readonly notifications?: Notifications;
40+
readonly logOption?: LogOption;
3041
}
3142

3243
export class EC2InstanceRunningScheduleStack extends Stack {
@@ -51,6 +62,22 @@ export class EC2InstanceRunningScheduleStack extends Stack {
5162
const machine = new RunningControlStateMachine(this, 'StateMachine', {
5263
stateMachineName: undefined,
5364
notificationTopic: topic,
65+
logs: (() => {
66+
if (props.logOption?.machineLogLevel) {
67+
return {
68+
destination: new logs.LogGroup(this, 'StateMachineLogGroup', {
69+
logGroupName: (() => {
70+
// if (names.stateMachineName) {
71+
// return `/aws/states/${names.stateMachineName}`;
72+
// }
73+
return undefined;
74+
})(),
75+
}),
76+
level: props.logOption.machineLogLevel,
77+
};
78+
}
79+
return undefined;
80+
})(),
5481
});
5582

5683
// 👇 EventBridge Scheduler IAM Role

test/__snapshots__/stack.specific.test.ts.snap

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/stack.specific.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { App } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
3-
import { EC2InstanceRunningScheduleStack } from '../src';
3+
import { EC2InstanceRunningScheduleStack, EC2InstanceRunningScheduleStackMachineLogLevel } from '../src';
44

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

@@ -29,6 +29,9 @@ describe('Ec2InstanceRunningScheduleStack specific Testing', () => {
2929
3030
],
3131
},
32+
logOption: {
33+
machineLogLevel: EC2InstanceRunningScheduleStackMachineLogLevel.ALL,
34+
},
3235
});
3336

3437
const template = Template.fromStack(stack);

0 commit comments

Comments
 (0)