11import { Stack } from 'aws-cdk-lib' ;
22import * as iam from 'aws-cdk-lib/aws-iam' ;
3+ import * as logs from 'aws-cdk-lib/aws-logs' ;
34import * as scheduler from 'aws-cdk-lib/aws-scheduler' ;
45import * as sns from 'aws-cdk-lib/aws-sns' ;
6+ import { LogLevel as EC2InstanceRunningScheduleStackMachineLogLevel } from 'aws-cdk-lib/aws-stepfunctions' ;
57import { Construct } from 'constructs' ;
68import { RunningControlStateMachine } from './resources/running-control-state-machine' ;
79
10+ export {
11+ EC2InstanceRunningScheduleStackMachineLogLevel ,
12+ } ;
13+
814export 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+
2535export interface EC2InstanceRunningScheduleStackProps {
2636 readonly targetResource : TargetResource ;
2737 readonly stopSchedule ?: Schedule ;
2838 readonly startSchedule ?: Schedule ;
2939 readonly notifications ?: Notifications ;
40+ readonly logOption ?: LogOption ;
3041}
3142
3243export 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
0 commit comments