-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(stepfunctions): disabling logging still requires LogGroup #30816
base: main
Are you sure you want to change the base?
Changes from 1 commit
b62fe80
3efbfba
3ca2073
f5b6d2c
6a0fb67
6dc606e
ef79c2c
e0aacb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ export interface LogOptions { | |
/** | ||
* The log group where the execution history events will be logged. | ||
*/ | ||
readonly destination: logs.ILogGroup; | ||
readonly destination?: logs.ILogGroup; | ||
|
||
/** | ||
* Determines whether execution data is included in your log. | ||
|
@@ -507,26 +507,32 @@ export class StateMachine extends StateMachineBase { | |
} | ||
|
||
private buildLoggingConfiguration(logOptions: LogOptions): CfnStateMachine.LoggingConfigurationProperty { | ||
// https://docs.aws.amazon.com/step-functions/latest/dg/cw-logs.html#cloudwatch-iam-policy | ||
this.addToRolePolicy(new iam.PolicyStatement({ | ||
effect: iam.Effect.ALLOW, | ||
actions: [ | ||
'logs:CreateLogDelivery', | ||
'logs:GetLogDelivery', | ||
'logs:UpdateLogDelivery', | ||
'logs:DeleteLogDelivery', | ||
'logs:ListLogDeliveries', | ||
'logs:PutResourcePolicy', | ||
'logs:DescribeResourcePolicies', | ||
'logs:DescribeLogGroups', | ||
], | ||
resources: ['*'], | ||
})); | ||
if (logOptions.level !== LogLevel.OFF && !logOptions.destination) { | ||
throw new Error('Logs destination is required when level is not OFF.'); | ||
} | ||
Comment on lines
+569
to
+571
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall this validation be done earlier (at line 427) with other validations instead?
reasons for ask:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a separate validation method validateLogOptions() |
||
|
||
if (logOptions.destination) { | ||
// https://docs.aws.amazon.com/step-functions/latest/dg/cw-logs.html#cloudwatch-iam-policy | ||
this.addToRolePolicy(new iam.PolicyStatement({ | ||
effect: iam.Effect.ALLOW, | ||
actions: [ | ||
'logs:CreateLogDelivery', | ||
'logs:GetLogDelivery', | ||
'logs:UpdateLogDelivery', | ||
'logs:DeleteLogDelivery', | ||
'logs:ListLogDeliveries', | ||
'logs:PutResourcePolicy', | ||
'logs:DescribeResourcePolicies', | ||
'logs:DescribeLogGroups', | ||
], | ||
resources: ['*'], | ||
})); | ||
} | ||
|
||
return { | ||
destinations: [{ | ||
destinations: logOptions.destination ? [{ | ||
cloudWatchLogsLogGroup: { logGroupArn: logOptions.destination.logGroupArn }, | ||
}], | ||
}] : undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we do this like as follows - will it reduce need to check
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated. |
||
includeExecutionData: logOptions.includeExecutionData, | ||
level: logOptions.level || 'ERROR', | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,6 +307,37 @@ describe('State Machine', () => { | |
}); | ||
}); | ||
|
||
test('log configuration with level OFF', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
new sfn.StateMachine(stack, 'MyStateMachine', { | ||
definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))), | ||
logs: { level: sfn.LogLevel.OFF }, | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', { | ||
DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}', | ||
LoggingConfiguration: { | ||
Level: 'OFF', | ||
}, | ||
}); | ||
}); | ||
|
||
test('log configuration throws when no destination specified', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
expect(() => { | ||
new sfn.StateMachine(stack, 'MyStateMachine', { | ||
definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we not directly pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's just a copy & paste. |
||
logs: { level: sfn.LogLevel.ERROR }, | ||
}); | ||
}).toThrow('Logs destination is required when level is not OFF.'); | ||
}); | ||
|
||
test('tracing configuration', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this not be a breaking change for existing usage? example:
Some user(s) might be utilising
ILogGroup
's public properties fromlogOptions
which will now cause issues because now such users will need to make non-null assertions before using such properties (e.g. with!
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the jsii-diff documentation:
So i think this change is not a breaking change.