From d472177ddfaea235ee157be01b1b8509470e49d0 Mon Sep 17 00:00:00 2001 From: Florian Eitel Date: Sun, 22 Mar 2020 18:54:15 +0100 Subject: [PATCH 1/9] feat(stepfunctions): Support logging configuration Fixes #5754 --- packages/@aws-cdk/aws-stepfunctions/README.md | 16 +++ .../aws-stepfunctions/lib/state-machine.ts | 84 +++++++++++++++ .../@aws-cdk/aws-stepfunctions/package.json | 2 + .../integ.stepfunctions-logging.expected.json | 102 ++++++++++++++++++ .../test/integ.stepfunctions-logging.ts | 20 ++++ .../test/test.state-machine.ts | 64 ++++++++++- 6 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.expected.json create mode 100644 packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.ts diff --git a/packages/@aws-cdk/aws-stepfunctions/README.md b/packages/@aws-cdk/aws-stepfunctions/README.md index 70defad102f9b..e131744c8ecc8 100644 --- a/packages/@aws-cdk/aws-stepfunctions/README.md +++ b/packages/@aws-cdk/aws-stepfunctions/README.md @@ -690,6 +690,22 @@ new cloudwatch.Alarm(this, 'ThrottledAlarm', { }); ``` +## Logging + +Enable logging to CloudWatch by passing a logging configuration with a +destination LogGroup: + +```ts +const log = new logs.LogGroup(stack, 'MyLogGroup'); + +new stepfunctions.StateMachine(stack, 'MyStateMachine', { + definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')), + loggingConfiguration: { + destinations: [log], + level: stepfunctions.LoggingLevel.ALL, + } +}); +``` ## Future work diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index efb9f5659c31d..f56a84ca5bb5c 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -1,5 +1,6 @@ import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as iam from '@aws-cdk/aws-iam'; +import * as logs from '@aws-cdk/aws-logs'; import { Construct, Duration, IResource, Resource, Stack } from '@aws-cdk/core'; import { StateGraph } from './state-graph'; import { CfnStateMachine } from './stepfunctions.generated'; @@ -24,6 +25,56 @@ export enum StateMachineType { STANDARD = 'STANDARD' } +/** + * Defines which category of execution history events are logged. + * + * @see https://docs.aws.amazon.com/step-functions/latest/dg/cloudwatch-log-level.html + * + * @default ERROR + */ +export enum LoggingLevel { + /** + * No Logging + */ + OFF = 'OFF', + /** + * Log everything + */ + ALL = 'ALL', + /** + * Log all errors + */ + ERROR= 'ERROR', + /** + * Log fatal errors + */ + FATAL = 'FATAL' +} + +/** + * Defines what execution history events are logged and where they are logged. + */ +export interface LoggingConfiguration { + /** + * An array of objects that describes where your execution history events will be logged. Limited to size 1. + */ + readonly destinations: logs.ILogGroup[]; + + /** + * Determines whether execution data is included in your log. + * + * @default true + */ + readonly includeExecutionData?: boolean; + + /** + * Defines which category of execution history events are logged. + * + * @default ERROR + */ + readonly level?: LoggingLevel; +} + /** * Properties for defining a State Machine */ @@ -60,6 +111,13 @@ export interface StateMachineProps { * @default StateMachineType.STANDARD */ readonly stateMachineType?: StateMachineType; + + /** + * Defines what execution history events are logged and where they are logged. + * + * @default No logging + */ + readonly loggingConfiguration?: LoggingConfiguration; } /** @@ -132,11 +190,37 @@ export class StateMachine extends StateMachineBase { this.stateMachineType = props.stateMachineType ? props.stateMachineType : StateMachineType.STANDARD; + let loggingConfiguration: CfnStateMachine.LoggingConfigurationProperty | undefined; + if (props.loggingConfiguration && props.loggingConfiguration.destinations.length > 0) { + const conf = props.loggingConfiguration; + loggingConfiguration = { + destinations: conf.destinations.map(loggroup => ({ cloudWatchLogsLogGroup: { logGroupArn: loggroup.logGroupArn } })), + includeExecutionData: conf.includeExecutionData, + level: conf.level || "ERROR" + }; + // 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: ["*"] + })); + } + const resource = new CfnStateMachine(this, 'Resource', { stateMachineName: this.physicalName, stateMachineType: props.stateMachineType ? props.stateMachineType : undefined, roleArn: this.role.roleArn, definitionString: Stack.of(this).toJsonString(graph.toGraphJson()), + loggingConfiguration }); resource.node.addDependency(this.role); diff --git a/packages/@aws-cdk/aws-stepfunctions/package.json b/packages/@aws-cdk/aws-stepfunctions/package.json index 8d53040da7428..c2941b6f2546e 100644 --- a/packages/@aws-cdk/aws-stepfunctions/package.json +++ b/packages/@aws-cdk/aws-stepfunctions/package.json @@ -74,6 +74,7 @@ "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/aws-events": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", + "@aws-cdk/aws-logs": "0.0.0", "@aws-cdk/core": "0.0.0", "constructs": "^2.0.0" }, @@ -82,6 +83,7 @@ "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/aws-events": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", + "@aws-cdk/aws-logs": "0.0.0", "@aws-cdk/core": "0.0.0", "constructs": "^2.0.0" }, diff --git a/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.expected.json b/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.expected.json new file mode 100644 index 0000000000000..303984e29f9f7 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.expected.json @@ -0,0 +1,102 @@ +{ + "Resources": { + "MyLogGroup5C0DAD85": { + "Type": "AWS::Logs::LogGroup", + "Properties": { + "RetentionInDays": 731 + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "MyStateMachineRoleD59FFEBC": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "states.", + { + "Ref": "AWS::Region" + }, + ".amazonaws.com" + ] + ] + } + } + } + ], + "Version": "2012-10-17" + } + } + }, + "MyStateMachineRoleDefaultPolicyE468EB18": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyStateMachineRoleDefaultPolicyE468EB18", + "Roles": [ + { + "Ref": "MyStateMachineRoleD59FFEBC" + } + ] + } + }, + "MyStateMachine6C968CA5": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": "{\"StartAt\":\"Pass\",\"States\":{\"Pass\":{\"Type\":\"Pass\",\"End\":true}}}", + "RoleArn": { + "Fn::GetAtt": [ + "MyStateMachineRoleD59FFEBC", + "Arn" + ] + }, + "LoggingConfiguration": { + "Destinations": [ + { + "CloudWatchLogsLogGroup": { + "LogGroupArn": { + "Fn::GetAtt": [ + "MyLogGroup5C0DAD85", + "Arn" + ] + } + } + } + ], + "IncludeExecutionData": false, + "Level": "FATAL" + } + }, + "DependsOn": [ + "MyStateMachineRoleDefaultPolicyE468EB18", + "MyStateMachineRoleD59FFEBC" + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.ts b/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.ts new file mode 100644 index 0000000000000..691c6c45a7716 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.ts @@ -0,0 +1,20 @@ +import * as logs from '@aws-cdk/aws-logs'; +import * as cdk from '@aws-cdk/core'; +import * as stepfunctions from "../lib"; + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'aws-cdk-stepfunctions-logging'); + +const log = new logs.LogGroup(stack, 'MyLogGroup'); + +new stepfunctions.StateMachine(stack, 'MyStateMachine', { + definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')), + loggingConfiguration: { + destinations: [log], + level: stepfunctions.LoggingLevel.FATAL, + includeExecutionData: false + } +}); + +app.synth(); diff --git a/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts index 2aab5ea1070d8..e78297daeabec 100644 --- a/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts @@ -1,4 +1,5 @@ import { expect, haveResource } from '@aws-cdk/assert'; +import * as logs from '@aws-cdk/aws-logs'; import * as cdk from '@aws-cdk/core'; import { Test } from 'nodeunit'; import * as stepfunctions from '../lib'; @@ -63,5 +64,66 @@ export = { })); test.done(); - } + }, + + 'Add log configuration'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const log = new logs.LogGroup(stack, 'MyLogGroup'); + + new stepfunctions.StateMachine(stack, 'MyStateMachine', { + definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')), + loggingConfiguration: { + destinations: [log], + level: stepfunctions.LoggingLevel.FATAL, + includeExecutionData: false + } + }); + + // THEN + expect(stack).to(haveResource('AWS::StepFunctions::StateMachine', { + DefinitionString: "{\"StartAt\":\"Pass\",\"States\":{\"Pass\":{\"Type\":\"Pass\",\"End\":true}}}", + LoggingConfiguration: { + Destinations: [{ + CloudWatchLogsLogGroup: { + LogGroupArn: { + "Fn::GetAtt": ["MyLogGroup5C0DAD85", "Arn"] + } + } + }], + IncludeExecutionData: false, + Level: "FATAL" + } + })); + + expect(stack).to(haveResource('AWS::IAM::Policy', { + PolicyDocument: { + Statement: [{ + Action: [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + Effect: "Allow", + Resource: "*" + }], + Version: "2012-10-17" + }, + PolicyName: "MyStateMachineRoleDefaultPolicyE468EB18", + Roles: [ + { + Ref: "MyStateMachineRoleD59FFEBC" + } + ] + })); + + test.done(); + }, }; From 2366d9d29511dcbe2ff5f780b3a081abd160e5ed Mon Sep 17 00:00:00 2001 From: workeitel Date: Wed, 25 Mar 2020 15:05:47 +0100 Subject: [PATCH 2/9] Update packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index f56a84ca5bb5c..2bf96147b7bd8 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -32,7 +32,7 @@ export enum StateMachineType { * * @default ERROR */ -export enum LoggingLevel { +export enum LogLevel { /** * No Logging */ From 3e31990a14c76d84e50800a6be39151f148437fe Mon Sep 17 00:00:00 2001 From: workeitel Date: Wed, 25 Mar 2020 15:05:55 +0100 Subject: [PATCH 3/9] Update packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index 2bf96147b7bd8..b592e43e25c66 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -54,7 +54,7 @@ export enum LogLevel { /** * Defines what execution history events are logged and where they are logged. */ -export interface LoggingConfiguration { +export interface LogOptions { /** * An array of objects that describes where your execution history events will be logged. Limited to size 1. */ From 2c5962e6db10dd26c672d37031e5ae18340b3303 Mon Sep 17 00:00:00 2001 From: workeitel Date: Wed, 25 Mar 2020 15:06:02 +0100 Subject: [PATCH 4/9] Update packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index b592e43e25c66..91998943fb661 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -117,7 +117,7 @@ export interface StateMachineProps { * * @default No logging */ - readonly loggingConfiguration?: LoggingConfiguration; + readonly logs?: LogOptions; } /** From c3cfcd32f3e0a147a54ac95470e16c48aa216655 Mon Sep 17 00:00:00 2001 From: workeitel Date: Wed, 25 Mar 2020 15:06:12 +0100 Subject: [PATCH 5/9] Update packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts index e78297daeabec..6b13629e14f77 100644 --- a/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts @@ -66,7 +66,7 @@ export = { test.done(); }, - 'Add log configuration'(test: Test) { + 'log configuration'(test: Test) { // GIVEN const stack = new cdk.Stack(); From 12e23aa6b2a9edefc3a2a80d18063e6dcc735600 Mon Sep 17 00:00:00 2001 From: Florian Eitel Date: Wed, 25 Mar 2020 15:11:11 +0100 Subject: [PATCH 6/9] Remove integration test for step functions logging Not needed according to the PR feedback. --- .../integ.stepfunctions-logging.expected.json | 102 ------------------ .../test/integ.stepfunctions-logging.ts | 20 ---- 2 files changed, 122 deletions(-) delete mode 100644 packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.expected.json delete mode 100644 packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.ts diff --git a/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.expected.json b/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.expected.json deleted file mode 100644 index 303984e29f9f7..0000000000000 --- a/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.expected.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "Resources": { - "MyLogGroup5C0DAD85": { - "Type": "AWS::Logs::LogGroup", - "Properties": { - "RetentionInDays": 731 - }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" - }, - "MyStateMachineRoleD59FFEBC": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": { - "Fn::Join": [ - "", - [ - "states.", - { - "Ref": "AWS::Region" - }, - ".amazonaws.com" - ] - ] - } - } - } - ], - "Version": "2012-10-17" - } - } - }, - "MyStateMachineRoleDefaultPolicyE468EB18": { - "Type": "AWS::IAM::Policy", - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "logs:CreateLogDelivery", - "logs:GetLogDelivery", - "logs:UpdateLogDelivery", - "logs:DeleteLogDelivery", - "logs:ListLogDeliveries", - "logs:PutResourcePolicy", - "logs:DescribeResourcePolicies", - "logs:DescribeLogGroups" - ], - "Effect": "Allow", - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "PolicyName": "MyStateMachineRoleDefaultPolicyE468EB18", - "Roles": [ - { - "Ref": "MyStateMachineRoleD59FFEBC" - } - ] - } - }, - "MyStateMachine6C968CA5": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "DefinitionString": "{\"StartAt\":\"Pass\",\"States\":{\"Pass\":{\"Type\":\"Pass\",\"End\":true}}}", - "RoleArn": { - "Fn::GetAtt": [ - "MyStateMachineRoleD59FFEBC", - "Arn" - ] - }, - "LoggingConfiguration": { - "Destinations": [ - { - "CloudWatchLogsLogGroup": { - "LogGroupArn": { - "Fn::GetAtt": [ - "MyLogGroup5C0DAD85", - "Arn" - ] - } - } - } - ], - "IncludeExecutionData": false, - "Level": "FATAL" - } - }, - "DependsOn": [ - "MyStateMachineRoleDefaultPolicyE468EB18", - "MyStateMachineRoleD59FFEBC" - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.ts b/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.ts deleted file mode 100644 index 691c6c45a7716..0000000000000 --- a/packages/@aws-cdk/aws-stepfunctions/test/integ.stepfunctions-logging.ts +++ /dev/null @@ -1,20 +0,0 @@ -import * as logs from '@aws-cdk/aws-logs'; -import * as cdk from '@aws-cdk/core'; -import * as stepfunctions from "../lib"; - -const app = new cdk.App(); - -const stack = new cdk.Stack(app, 'aws-cdk-stepfunctions-logging'); - -const log = new logs.LogGroup(stack, 'MyLogGroup'); - -new stepfunctions.StateMachine(stack, 'MyStateMachine', { - definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')), - loggingConfiguration: { - destinations: [log], - level: stepfunctions.LoggingLevel.FATAL, - includeExecutionData: false - } -}); - -app.synth(); From b8bf577a6172ef335b1967b7db033b39c193ceef Mon Sep 17 00:00:00 2001 From: Florian Eitel Date: Wed, 25 Mar 2020 15:31:41 +0100 Subject: [PATCH 7/9] Incorporate PR feedback --- .../@aws-cdk/aws-stepfunctions/lib/state-machine.ts | 10 +++++----- .../aws-stepfunctions/test/test.state-machine.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index 91998943fb661..1d7598a4c446f 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -58,7 +58,7 @@ export interface LogOptions { /** * An array of objects that describes where your execution history events will be logged. Limited to size 1. */ - readonly destinations: logs.ILogGroup[]; + readonly destinations: logs.ILogGroup; /** * Determines whether execution data is included in your log. @@ -72,7 +72,7 @@ export interface LogOptions { * * @default ERROR */ - readonly level?: LoggingLevel; + readonly level?: LogLevel; } /** @@ -191,10 +191,10 @@ export class StateMachine extends StateMachineBase { this.stateMachineType = props.stateMachineType ? props.stateMachineType : StateMachineType.STANDARD; let loggingConfiguration: CfnStateMachine.LoggingConfigurationProperty | undefined; - if (props.loggingConfiguration && props.loggingConfiguration.destinations.length > 0) { - const conf = props.loggingConfiguration; + if (props.logs) { + const conf = props.logs; loggingConfiguration = { - destinations: conf.destinations.map(loggroup => ({ cloudWatchLogsLogGroup: { logGroupArn: loggroup.logGroupArn } })), + destinations: [{ cloudWatchLogsLogGroup: { logGroupArn: conf.destinations.logGroupArn } }], includeExecutionData: conf.includeExecutionData, level: conf.level || "ERROR" }; diff --git a/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts index 6b13629e14f77..370c4a42feb9c 100644 --- a/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts @@ -75,9 +75,9 @@ export = { new stepfunctions.StateMachine(stack, 'MyStateMachine', { definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')), - loggingConfiguration: { - destinations: [log], - level: stepfunctions.LoggingLevel.FATAL, + logs: { + destinations: log, + level: stepfunctions.LogLevel.FATAL, includeExecutionData: false } }); From 003b63d506fbd7451b19caf97df4fa167984008b Mon Sep 17 00:00:00 2001 From: Florian Eitel Date: Wed, 25 Mar 2020 16:11:43 +0100 Subject: [PATCH 8/9] Fix README.md --- packages/@aws-cdk/aws-stepfunctions/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions/README.md b/packages/@aws-cdk/aws-stepfunctions/README.md index e131744c8ecc8..f04bfaa8646ed 100644 --- a/packages/@aws-cdk/aws-stepfunctions/README.md +++ b/packages/@aws-cdk/aws-stepfunctions/README.md @@ -700,9 +700,9 @@ const log = new logs.LogGroup(stack, 'MyLogGroup'); new stepfunctions.StateMachine(stack, 'MyStateMachine', { definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')), - loggingConfiguration: { - destinations: [log], - level: stepfunctions.LoggingLevel.ALL, + logs: { + destinations: log, + level: stepfunctions.LogLevel.ALL, } }); ``` From bb6f9fdf85f26e46603b17c6a0ef2cd6e754dee1 Mon Sep 17 00:00:00 2001 From: Florian Eitel Date: Mon, 30 Mar 2020 23:40:06 +0200 Subject: [PATCH 9/9] PR fixes --- packages/@aws-cdk/aws-stepfunctions/README.md | 4 +-- .../aws-stepfunctions/lib/state-machine.ts | 26 +++++++------- .../test/test.state-machine.ts | 36 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions/README.md b/packages/@aws-cdk/aws-stepfunctions/README.md index f04bfaa8646ed..ef3af0ac4a97a 100644 --- a/packages/@aws-cdk/aws-stepfunctions/README.md +++ b/packages/@aws-cdk/aws-stepfunctions/README.md @@ -696,12 +696,12 @@ Enable logging to CloudWatch by passing a logging configuration with a destination LogGroup: ```ts -const log = new logs.LogGroup(stack, 'MyLogGroup'); +const logGroup = new logs.LogGroup(stack, 'MyLogGroup'); new stepfunctions.StateMachine(stack, 'MyStateMachine', { definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')), logs: { - destinations: log, + destinations: logGroup, level: stepfunctions.LogLevel.ALL, } }); diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index 1d7598a4c446f..e60c2a29a3eb3 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -56,9 +56,9 @@ export enum LogLevel { */ export interface LogOptions { /** - * An array of objects that describes where your execution history events will be logged. Limited to size 1. + * The log group where the execution history events will be logged. */ - readonly destinations: logs.ILogGroup; + readonly destination: logs.ILogGroup; /** * Determines whether execution data is included in your log. @@ -194,24 +194,24 @@ export class StateMachine extends StateMachineBase { if (props.logs) { const conf = props.logs; loggingConfiguration = { - destinations: [{ cloudWatchLogsLogGroup: { logGroupArn: conf.destinations.logGroupArn } }], + destinations: [{ cloudWatchLogsLogGroup: { logGroupArn: conf.destination.logGroupArn } }], includeExecutionData: conf.includeExecutionData, - level: conf.level || "ERROR" + level: conf.level || 'ERROR' }; // 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" + 'logs:CreateLogDelivery', + 'logs:GetLogDelivery', + 'logs:UpdateLogDelivery', + 'logs:DeleteLogDelivery', + 'logs:ListLogDeliveries', + 'logs:PutResourcePolicy', + 'logs:DescribeResourcePolicies', + 'logs:DescribeLogGroups' ], - resources: ["*"] + resources: ['*'] })); } diff --git a/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts index 370c4a42feb9c..ab1aaf1b46263 100644 --- a/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/test/test.state-machine.ts @@ -71,12 +71,12 @@ export = { const stack = new cdk.Stack(); // WHEN - const log = new logs.LogGroup(stack, 'MyLogGroup'); + const logGroup = new logs.LogGroup(stack, 'MyLogGroup'); new stepfunctions.StateMachine(stack, 'MyStateMachine', { definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')), logs: { - destinations: log, + destination: logGroup, level: stepfunctions.LogLevel.FATAL, includeExecutionData: false } @@ -84,17 +84,17 @@ export = { // THEN expect(stack).to(haveResource('AWS::StepFunctions::StateMachine', { - DefinitionString: "{\"StartAt\":\"Pass\",\"States\":{\"Pass\":{\"Type\":\"Pass\",\"End\":true}}}", + DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}', LoggingConfiguration: { Destinations: [{ CloudWatchLogsLogGroup: { LogGroupArn: { - "Fn::GetAtt": ["MyLogGroup5C0DAD85", "Arn"] + 'Fn::GetAtt': ['MyLogGroup5C0DAD85', 'Arn'] } } }], IncludeExecutionData: false, - Level: "FATAL" + Level: 'FATAL' } })); @@ -102,24 +102,24 @@ export = { PolicyDocument: { Statement: [{ Action: [ - "logs:CreateLogDelivery", - "logs:GetLogDelivery", - "logs:UpdateLogDelivery", - "logs:DeleteLogDelivery", - "logs:ListLogDeliveries", - "logs:PutResourcePolicy", - "logs:DescribeResourcePolicies", - "logs:DescribeLogGroups" + 'logs:CreateLogDelivery', + 'logs:GetLogDelivery', + 'logs:UpdateLogDelivery', + 'logs:DeleteLogDelivery', + 'logs:ListLogDeliveries', + 'logs:PutResourcePolicy', + 'logs:DescribeResourcePolicies', + 'logs:DescribeLogGroups' ], - Effect: "Allow", - Resource: "*" + Effect: 'Allow', + Resource: '*' }], - Version: "2012-10-17" + Version: '2012-10-17' }, - PolicyName: "MyStateMachineRoleDefaultPolicyE468EB18", + PolicyName: 'MyStateMachineRoleDefaultPolicyE468EB18', Roles: [ { - Ref: "MyStateMachineRoleD59FFEBC" + Ref: 'MyStateMachineRoleD59FFEBC' } ] }));