diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine-string.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine-string.ts new file mode 100644 index 0000000000000..f578b74793e4f --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine-string.ts @@ -0,0 +1,15 @@ +import * as cdk from 'aws-cdk-lib'; +import * as sfn from 'aws-cdk-lib/aws-stepfunctions'; +/* + * Stack verification steps: + * + * -- aws stepfunctions describe-state-machine --state-machine-arn has a status of `ACTIVE` and the definition is correct + */ +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'aws-stepfunctions-integ'); + +new sfn.StateMachine(stack, 'StateMachine', { + definitionBody: sfn.DefinitionBody.fromString('{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}'), +}); + +app.synth(); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/integrations/stepfunctions.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/integrations/stepfunctions.test.ts index 607298294d9cd..0f2a5c65bcf9a 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/integrations/stepfunctions.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/integrations/stepfunctions.test.ts @@ -304,7 +304,7 @@ describe('StepFunctionsIntegration', () => { }); const stateMachine: sfn.IStateMachine = new StateMachine(stack, 'StateMachine', { - definition: passTask, + definitionBody: sfn.DefinitionBody.fromChainable(passTask), stateMachineType: sfn.StateMachineType.EXPRESS, }); @@ -327,7 +327,7 @@ describe('StepFunctionsIntegration', () => { }); const stateMachine: sfn.IStateMachine = new StateMachine(stack, 'StateMachine', { - definition: passTask, + definitionBody: sfn.DefinitionBody.fromChainable(passTask), stateMachineType: sfn.StateMachineType.EXPRESS, }); @@ -362,7 +362,7 @@ describe('StepFunctionsIntegration', () => { const restapi = new apigw.RestApi(stack, 'RestApi'); const method = restapi.root.addMethod('ANY'); const stateMachine: sfn.StateMachine = new StateMachine(stack, 'StateMachine', { - definition: new sfn.Pass(stack, 'passTask'), + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Pass(stack, 'passTask')), stateMachineType: StateMachineType.STANDARD, }); const integration = apigw.StepFunctionsIntegration.startExecution(stateMachine); @@ -382,7 +382,7 @@ function givenSetup() { }); const stateMachine: sfn.IStateMachine = new StateMachine(stack, 'StateMachine', { - definition: passTask, + definitionBody: sfn.DefinitionBody.fromChainable(passTask), stateMachineType: sfn.StateMachineType.EXPRESS, }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/stepfunctions-api.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/stepfunctions-api.test.ts index 4bdacef692ad8..b73ec6a54e777 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/stepfunctions-api.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/stepfunctions-api.test.ts @@ -1,6 +1,6 @@ import { Template } from '../../assertions'; import * as sfn from '../../aws-stepfunctions'; -import { StateMachine } from '../../aws-stepfunctions'; +import { StateMachine, DefinitionBody } from '../../aws-stepfunctions'; import * as cdk from '../../core'; import * as apigw from '../lib'; import { StepFunctionsIntegration } from '../lib'; @@ -82,7 +82,7 @@ describe('Step Functions api', () => { const api = new apigw.RestApi(stack, 'Api'); const stateMachine = new sfn.StateMachine(stack, 'StateMachine', { stateMachineType: sfn.StateMachineType.EXPRESS, - definition: new sfn.Pass(stack, 'Pass'), + definitionBody: DefinitionBody.fromChainable(new sfn.Pass(stack, 'Pass')), }); // WHEN @@ -180,7 +180,7 @@ describe('Step Functions api', () => { }); const stateMachine: sfn.IStateMachine = new StateMachine(stack, 'StateMachine', { - definition: passTask, + definitionBody: DefinitionBody.fromChainable(passTask), stateMachineType: sfn.StateMachineType.STANDARD, }); @@ -199,14 +199,14 @@ function givenSetup() { }); const stateMachine: sfn.IStateMachine = new StateMachine(stack, 'StateMachine', { - definition: passTask, + definitionBody: DefinitionBody.fromChainable(passTask), stateMachineType: sfn.StateMachineType.EXPRESS, }); return { stack, stateMachine }; } -function whenCondition(stack:cdk.Stack, stateMachine: sfn.IStateMachine) { +function whenCondition(stack: cdk.Stack, stateMachine: sfn.IStateMachine) { const api = new apigw.StepFunctionsRestApi(stack, 'StepFunctionsRestApi', { stateMachine: stateMachine }); return api; } diff --git a/packages/aws-cdk-lib/aws-codepipeline-actions/test/stepfunctions/stepfunctions-invoke-actions.test.ts b/packages/aws-cdk-lib/aws-codepipeline-actions/test/stepfunctions/stepfunctions-invoke-actions.test.ts index 636e6472a8779..6fd457125e362 100644 --- a/packages/aws-cdk-lib/aws-codepipeline-actions/test/stepfunctions/stepfunctions-invoke-actions.test.ts +++ b/packages/aws-cdk-lib/aws-codepipeline-actions/test/stepfunctions/stepfunctions-invoke-actions.test.ts @@ -147,7 +147,7 @@ function minimalPipeline(stack: Stack): codepipeline.IStage { const sourceOutput = new codepipeline.Artifact(); const startState = new stepfunction.Pass(stack, 'StartState'); const simpleStateMachine = new stepfunction.StateMachine(stack, 'SimpleStateMachine', { - definition: startState, + definitionBody: stepfunction.DefinitionBody.fromChainable(startState), }); const pipeline = new codepipeline.Pipeline(stack, 'MyPipeline'); const sourceStage = pipeline.addStage({ diff --git a/packages/aws-cdk-lib/aws-events-targets/test/stepfunctions/statemachine.test.ts b/packages/aws-cdk-lib/aws-events-targets/test/stepfunctions/statemachine.test.ts index 33099f2558fef..410f51801646e 100644 --- a/packages/aws-cdk-lib/aws-events-targets/test/stepfunctions/statemachine.test.ts +++ b/packages/aws-cdk-lib/aws-events-targets/test/stepfunctions/statemachine.test.ts @@ -13,7 +13,7 @@ test('State machine can be used as Event Rule target', () => { schedule: events.Schedule.rate(cdk.Duration.minutes(1)), }); const stateMachine = new sfn.StateMachine(stack, 'SM', { - definition: new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) }), + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) })), }); // WHEN @@ -67,7 +67,7 @@ test('Existing role can be used for State machine Rule target', () => { assumedBy: new iam.ServicePrincipal('events.amazonaws.com'), }); const stateMachine = new sfn.StateMachine(stack, 'SM', { - definition: new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) }), + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) })), }); // WHEN @@ -124,7 +124,7 @@ test('specifying retry policy', () => { assumedBy: new iam.ServicePrincipal('events.amazonaws.com'), }); const stateMachine = new sfn.StateMachine(stack, 'SM', { - definition: new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) }), + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) })), }); rule.addTarget(new targets.SfnStateMachine(stateMachine, { @@ -172,7 +172,7 @@ test('specifying retry policy with 0 retryAttempts', () => { assumedBy: new iam.ServicePrincipal('events.amazonaws.com'), }); const stateMachine = new sfn.StateMachine(stack, 'SM', { - definition: new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) }), + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) })), }); rule.addTarget(new targets.SfnStateMachine(stateMachine, { @@ -221,7 +221,7 @@ test('use a Dead Letter Queue for the rule target', () => { assumedBy: new iam.ServicePrincipal('events.amazonaws.com'), }); const stateMachine = new sfn.StateMachine(stack, 'SM', { - definition: new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) }), + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Wait(stack, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) })), }); // WHEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/athena/start-query-execution.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/athena/start-query-execution.test.ts index 22e5316ee9985..2d9be071b0e88 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/athena/start-query-execution.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/athena/start-query-execution.test.ts @@ -192,7 +192,7 @@ describe('Start Query Execution', () => { }); new sfn.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/aws-sdk/call-aws-service.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/aws-sdk/call-aws-service.test.ts index cce87e2739337..cd5ac68818c15 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/aws-sdk/call-aws-service.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/aws-sdk/call-aws-service.test.ts @@ -24,7 +24,7 @@ test('CallAwsService task', () => { }); new sfn.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -73,7 +73,7 @@ test('with custom IAM action', () => { }); new sfn.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -118,7 +118,7 @@ test('with unresolved tokens', () => { }); new sfn.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -176,7 +176,7 @@ test('can pass additional IAM statements', () => { }); new sfn.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -212,7 +212,7 @@ test('IAM policy for sfn', () => { }); new sfn.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/ecs/ecs-tasks.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/ecs/ecs-tasks.test.ts index 5aea07ea8766c..b05db95c4472e 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/ecs/ecs-tasks.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/ecs/ecs-tasks.test.ts @@ -78,7 +78,7 @@ describeDeprecated('ecs-tasks', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: runTask, + definitionBody: sfn.DefinitionBody.fromChainable(runTask), }); // THEN @@ -191,7 +191,7 @@ describeDeprecated('ecs-tasks', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: runTask, + definitionBody: sfn.DefinitionBody.fromChainable(runTask), }); // THEN @@ -292,7 +292,7 @@ describeDeprecated('ecs-tasks', () => { const runTask = new sfn.Task(stack, 'Run', { task: ec2Task }); new sfn.StateMachine(stack, 'SM', { - definition: runTask, + definitionBody: sfn.DefinitionBody.fromChainable(runTask), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/ecs/run-tasks.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/ecs/run-tasks.test.ts index bb5214cd613fd..957c4820bf087 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/ecs/run-tasks.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/ecs/run-tasks.test.ts @@ -113,18 +113,18 @@ test('Running a task with container override and container has explicitly set a ], launchTarget: new tasks.EcsFargateLaunchTarget(), }).toStateJson())).toHaveProperty('Parameters.Overrides', { - ContainerOverrides: [ - { - Environment: [ - { - Name: 'SOME_KEY', - 'Value.$': '$.SomeKey', - }, - ], - Name: 'ExplicitContainerName', - }, - ], - }); + ContainerOverrides: [ + { + Environment: [ + { + Name: 'SOME_KEY', + 'Value.$': '$.SomeKey', + }, + ], + Name: 'ExplicitContainerName', + }, + ], + }); }); test('Running a task without propagated tag source', () => { @@ -235,7 +235,7 @@ test('Running a Fargate Task', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: runTask, + definitionBody: sfn.DefinitionBody.fromChainable(runTask), }); // THEN @@ -364,7 +364,7 @@ test('Running an EC2 Task with bridge network', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: runTask, + definitionBody: sfn.DefinitionBody.fromChainable(runTask), }); // THEN @@ -483,7 +483,7 @@ test('Running an EC2 Task with placement strategies', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: runTask, + definitionBody: sfn.DefinitionBody.fromChainable(runTask), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-add-step.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-add-step.test.ts index d6678cb09b9d9..5e3e2b8674bb7 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-add-step.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-add-step.test.ts @@ -301,7 +301,7 @@ test('task policies are generated', () => { integrationPattern: sfn.IntegrationPattern.RUN_JOB, }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-cancel-step.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-cancel-step.test.ts index 812a8fdfac616..1036b4313512f 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-cancel-step.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-cancel-step.test.ts @@ -47,7 +47,7 @@ test('task policies are generated', () => { stepId: 'StepId', }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-modify-instance-fleet-by-name.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-modify-instance-fleet-by-name.test.ts index f64864ba6ae71..050a069b2f3d7 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-modify-instance-fleet-by-name.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-modify-instance-fleet-by-name.test.ts @@ -55,7 +55,7 @@ test('task policies are generated', () => { targetSpotCapacity: 0, }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-modify-instance-group-by-name.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-modify-instance-group-by-name.test.ts index d38b820502d2d..e411bf3e5c7e6 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-modify-instance-group-by-name.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-modify-instance-group-by-name.test.ts @@ -91,7 +91,7 @@ test('task policies are generated', () => { }, }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-set-cluster-termination-protection.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-set-cluster-termination-protection.test.ts index 9c313754d7cf1..ee757f09fe1e7 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-set-cluster-termination-protection.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-set-cluster-termination-protection.test.ts @@ -47,7 +47,7 @@ test('task policies are generated', () => { terminationProtected: false, }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-terminate-cluster.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-terminate-cluster.test.ts index 11e3eb8320d8c..2a7aa6e53e80b 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-terminate-cluster.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-terminate-cluster.test.ts @@ -46,7 +46,7 @@ test('task policies are generated', () => { integrationPattern: sfn.IntegrationPattern.RUN_JOB, }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/create-virtual-cluster.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/create-virtual-cluster.test.ts index 0a8b5c35618ac..4abfba223ef3d 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/create-virtual-cluster.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/create-virtual-cluster.test.ts @@ -21,7 +21,7 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -65,7 +65,7 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -132,7 +132,7 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -154,7 +154,7 @@ test('Permitted role actions included for CreateVirtualCluster if service integr }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/delete-virtual-cluster.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/delete-virtual-cluster.test.ts index 4f29217158029..9451544def370 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/delete-virtual-cluster.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/delete-virtual-cluster.test.ts @@ -92,7 +92,7 @@ describe('Valid policy statements and resources are passed ', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -134,7 +134,7 @@ describe('Valid policy statements and resources are passed ', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -179,7 +179,7 @@ describe('Valid policy statements and resources are passed ', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/start-job-run.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/start-job-run.test.ts index 5c96170ba76a5..67f37ba04e8a1 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/start-job-run.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emrcontainers/start-job-run.test.ts @@ -747,7 +747,7 @@ describe('Invoke EMR Containers Start Job Run with ', () => { const task = new EmrContainersStartJobRun(stack, 'EMR Containers Start Job Run', defaultProps); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -827,7 +827,7 @@ describe('Invoke EMR Containers Start Job Run with ', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -901,7 +901,7 @@ describe('Invoke EMR Containers Start Job Run with ', () => { }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -950,7 +950,7 @@ describe('Invoke EMR Containers Start Job Run with ', () => { const task = new EmrContainersStartJobRun(stack, 'Task', defaultProps); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -982,7 +982,7 @@ describe('Invoke EMR Containers Start Job Run with ', () => { const task = new EmrContainersStartJobRun(stack, 'Task', defaultProps); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/evaluate-expression.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/evaluate-expression.test.ts index 4d3f87124cbd5..c27376701228b 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/evaluate-expression.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/evaluate-expression.test.ts @@ -15,7 +15,7 @@ test('Eval with Node.js', () => { expression: '$.a + $.b', }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -52,7 +52,7 @@ test('expression does not contain paths', () => { expression: '2 + 2', }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', { @@ -77,7 +77,7 @@ test('with dash and underscore in path', () => { expression: '$.a_b + $.c-d + $[_e]', }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', { diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts index 529a8032c8e01..67e98c798d32e 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts @@ -142,7 +142,7 @@ describe('Put Events', () => { source: 'my.source', }], }); - // THEN + // THEN }).toThrowError('Task Token is required in `entries`. Use JsonPath.taskToken to set the token.'); }); @@ -157,7 +157,7 @@ describe('Put Events', () => { source: 'my.source', }], }); - // THEN + // THEN }).toThrowError('Unsupported service integration pattern'); }); @@ -235,7 +235,7 @@ describe('Put Events', () => { source: 'my.source', }], }); - new sfn.StateMachine(stack, 'State Machine', { definition: task }); + new sfn.StateMachine(stack, 'State Machine', { definitionBody: sfn.DefinitionBody.fromChainable(task) }); // THEN Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/glue/run-glue-job-task.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/glue/run-glue-job-task.test.ts index eb46ac79eba49..a448648860d1f 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/glue/run-glue-job-task.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/glue/run-glue-job-task.test.ts @@ -16,7 +16,7 @@ describeDeprecated('RunGlueJobTask', () => { task: new tasks.RunGlueJobTask(jobName), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -59,7 +59,7 @@ describeDeprecated('RunGlueJobTask', () => { }), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -96,7 +96,7 @@ describeDeprecated('RunGlueJobTask', () => { }), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { @@ -115,7 +115,7 @@ describeDeprecated('RunGlueJobTask', () => { }), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/glue/start-job-run.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/glue/start-job-run.test.ts index d6c17d111db42..f1a79d2226c6f 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/glue/start-job-run.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/glue/start-job-run.test.ts @@ -15,7 +15,7 @@ test('Invoke glue job with just job ARN', () => { glueJobName, }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -57,7 +57,7 @@ test('Invoke glue job with full properties', () => { notifyDelayAfter, }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -93,7 +93,7 @@ test('Invoke glue job with Timeout.at()', () => { taskTimeout: sfn.Timeout.at('$.timeout'), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -125,7 +125,7 @@ test('job arguments can reference state input', () => { arguments: sfn.TaskInput.fromJsonPathAt('$.input'), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -157,7 +157,7 @@ test('permitted role actions limited to start job run if service integration pat }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { @@ -176,7 +176,7 @@ test('permitted role actions include start, get, and stop job run if service int }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/invoke-activity.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/invoke-activity.test.ts index 7945ae85ac32a..201fa6b11b980 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/invoke-activity.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/invoke-activity.test.ts @@ -6,14 +6,14 @@ import * as tasks from '../lib'; describeDeprecated('InvokeActivity', () => { test('Activity can be used in a Task', () => { - // GIVEN + // GIVEN const stack = new Stack(); // WHEN const activity = new sfn.Activity(stack, 'Activity'); const task = new sfn.Task(stack, 'Task', { task: new tasks.InvokeActivity(activity) }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -29,7 +29,7 @@ describeDeprecated('InvokeActivity', () => { }); test('Activity Task metrics and Activity metrics are the same', () => { - // GIVEN + // GIVEN const stack = new Stack(); const activity = new sfn.Activity(stack, 'Activity'); const task = new sfn.Task(stack, 'Invoke', { task: new tasks.InvokeActivity(activity) }); diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke-function.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke-function.test.ts index c13b0e43f87c8..0a5d1bb906100 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke-function.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke-function.test.ts @@ -18,10 +18,10 @@ beforeEach(() => { describeDeprecated('InvokeFunction', () => { test('Invoke lambda with function ARN', () => { - // WHEN + // WHEN const task = new sfn.Task(stack, 'Task', { task: new tasks.InvokeFunction(fn) }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN @@ -38,13 +38,13 @@ describeDeprecated('InvokeFunction', () => { test('Lambda function payload ends up in Parameters', () => { new sfn.StateMachine(stack, 'SM', { - definition: new sfn.Task(stack, 'Task', { + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Task(stack, 'Task', { task: new tasks.InvokeFunction(fn, { payload: { foo: sfn.JsonPath.stringAt('$.bar'), }, }), - }), + })), }); Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', { diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/run-lambda-task.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/run-lambda-task.test.ts index 9ff46be34b2a2..679a75ba535a4 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/run-lambda-task.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/run-lambda-task.test.ts @@ -29,7 +29,7 @@ describeDeprecated('run lambda task', () => { }), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -71,7 +71,7 @@ describeDeprecated('run lambda task', () => { }), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -165,7 +165,7 @@ describeDeprecated('run lambda task', () => { task: new tasks.RunLambdaTask(fn), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -199,7 +199,7 @@ describeDeprecated('run lambda task', () => { }), }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/start-execution.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/start-execution.test.ts index 5006a253013a3..229638f1b9b81 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/start-execution.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/start-execution.test.ts @@ -9,7 +9,7 @@ let child: sfn.StateMachine; beforeEach(() => { stack = new Stack(); child = new sfn.StateMachine(stack, 'ChildStateMachine', { - definition: sfn.Chain.start(new sfn.Pass(stack, 'PassState')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'PassState'))), }); }); @@ -25,7 +25,7 @@ describeDeprecated('StartExecution', () => { }); new sfn.StateMachine(stack, 'ParentStateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -63,7 +63,7 @@ describeDeprecated('StartExecution', () => { }); new sfn.StateMachine(stack, 'ParentStateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -189,7 +189,7 @@ describeDeprecated('StartExecution', () => { }); new sfn.StateMachine(stack, 'ParentStateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/stepfunctions/invoke-activity.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/stepfunctions/invoke-activity.test.ts index c754775793aad..04137893c6d7a 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/stepfunctions/invoke-activity.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/stepfunctions/invoke-activity.test.ts @@ -11,7 +11,7 @@ test('Activity can be used in a Task', () => { const activity = new sfn.Activity(stack, 'Activity'); const task = new StepFunctionsInvokeActivity(stack, 'Task', { activity }); new sfn.StateMachine(stack, 'SM', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/stepfunctions/start-execution.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/stepfunctions/start-execution.test.ts index e21ee044937fe..67bdf340d9af4 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/stepfunctions/start-execution.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/stepfunctions/start-execution.test.ts @@ -8,7 +8,7 @@ let child: sfn.StateMachine; beforeEach(() => { stack = new Stack(); child = new sfn.StateMachine(stack, 'ChildStateMachine', { - definition: sfn.Chain.start(new sfn.Pass(stack, 'PassState')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'PassState'))), }); }); @@ -22,7 +22,7 @@ test('Execute State Machine - Default - Request Response', () => { }); new sfn.StateMachine(stack, 'ParentStateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -59,7 +59,7 @@ test('Execute State Machine - Run Job', () => { }); new sfn.StateMachine(stack, 'ParentStateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -178,7 +178,7 @@ test('Execute State Machine - Wait For Task Token', () => { }); new sfn.StateMachine(stack, 'ParentStateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toEqual({ @@ -226,7 +226,7 @@ test('Execute State Machine - Associate With Parent - Input Provided', () => { }); new sfn.StateMachine(stack, 'ParentStateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toMatchObject({ @@ -246,7 +246,7 @@ test('Execute State Machine - Associate With Parent - Input Not Provided', () => }); new sfn.StateMachine(stack, 'ParentStateMachine', { - definition: task, + definitionBody: sfn.DefinitionBody.fromChainable(task), }); expect(stack.resolve(task.toStateJson())).toMatchObject({ diff --git a/packages/aws-cdk-lib/aws-stepfunctions/README.md b/packages/aws-cdk-lib/aws-stepfunctions/README.md index f944e0627c617..57e6b61d47665 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions/README.md +++ b/packages/aws-cdk-lib/aws-stepfunctions/README.md @@ -95,6 +95,18 @@ existing one as well. Set the `removalPolicy` prop to `RemovalPolicy.RETAIN` if you want to retain the execution history when CloudFormation deletes your state machine. +Alternatively you can specify an existing step functions definition by providing a string or a file that contains the ASL JSON. + +```ts +new sfn.StateMachine(stack, 'StateMachineFromString', { + definitionBody: sfn.DefinitionBody.fromString('{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}'), +}); + +new sfn.StateMachine(stack, 'StateMachineFromFile', { + definitionBody: sfn.DefinitionBody.fromFile('./asl.json'), +}); +``` + ## State Machine Data An Execution represents each time the State Machine is run. Every Execution has [State Machine diff --git a/packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts b/packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts index 1a46d90c49eba..fb7fc5a007ca6 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts @@ -3,6 +3,7 @@ import { StateGraph } from './state-graph'; import { StatesMetrics } from './stepfunctions-canned-metrics.generated'; import { CfnStateMachine } from './stepfunctions.generated'; import { IChainable } from './types'; +import * as s3_assets from '../../aws-s3-assets'; import * as cloudwatch from '../../aws-cloudwatch'; import * as iam from '../../aws-iam'; import * as logs from '../../aws-logs'; @@ -90,8 +91,19 @@ export interface StateMachineProps { /** * Definition for this state machine + * @deprecated use definitionBody: DefinitionBody.fromChainable() */ - readonly definition: IChainable; + readonly definition?: IChainable; + + /** + * Definition for this state machine + */ + readonly definitionBody?: DefinitionBody; + + /** + * substitutions for the definition body aas a key-value map + */ + readonly definitionSubstitutions?: { [key: string]: string }; /** * The execution role for the state machine service @@ -400,6 +412,13 @@ export class StateMachine extends StateMachineBase { physicalName: props.stateMachineName, }); + if (props.definition && props.definitionBody) { + throw new Error('Cannot specify definition and definitionBody at the same time'); + } + if (!props.definition && !props.definitionBody) { + throw new Error('You need to specify either definition or definitionBody'); + } + if (props.stateMachineName !== undefined) { this.validateStateMachineName(props.stateMachineName); } @@ -408,8 +427,7 @@ export class StateMachine extends StateMachineBase { assumedBy: new iam.ServicePrincipal('states.amazonaws.com'), }); - const graph = new StateGraph(props.definition.startState, `State Machine ${id} definition`); - graph.timeout = props.timeout; + const definitionBody = props.definitionBody ?? DefinitionBody.fromChainable(props.definition!); this.stateMachineType = props.stateMachineType ?? StateMachineType.STANDARD; @@ -417,18 +435,15 @@ export class StateMachine extends StateMachineBase { stateMachineName: this.physicalName, stateMachineType: props.stateMachineType ?? undefined, roleArn: this.role.roleArn, - definitionString: Stack.of(this).toJsonString(graph.toGraphJson()), loggingConfiguration: props.logs ? this.buildLoggingConfiguration(props.logs) : undefined, tracingConfiguration: props.tracingEnabled ? this.buildTracingConfiguration() : undefined, + ...definitionBody.bind(this, this.role, props), + definitionSubstitutions: props.definitionSubstitutions, }); resource.applyRemovalPolicy(props.removalPolicy, { default: RemovalPolicy.DESTROY }); resource.node.addDependency(this.role); - for (const statement of graph.policyStatements) { - this.addToRolePolicy(statement); - } - this.stateMachineName = this.getResourceNameAttribute(resource.attrName); this.stateMachineArn = this.getResourceArnAttribute(resource.ref, { service: 'states', @@ -621,3 +636,84 @@ export interface IStateMachine extends IResource, iam.IGrantable { */ metricTime(props?: cloudwatch.MetricOptions): cloudwatch.Metric; } + +/** + * Partial object from the StateMachine L1 construct properties containing definition information + */ +export interface DefinitionConfig { + readonly definition?: any; + readonly definitionString?: string; + readonly definitionS3Location?: CfnStateMachine.S3LocationProperty; +} + + +export abstract class DefinitionBody { + + public static fromFile(path: string, options: s3_assets.AssetOptions): DefinitionBody { + return new FileDefinitionBody(path, options); + } + + public static fromString(definition: string): DefinitionBody { + return new StringDefinitionBody(definition); + } + + public static fromChainable(chainable: IChainable): DefinitionBody { + return new ChainDefinitionBody(chainable); + } + + public abstract bind(scope: Construct, sfnPrincipal: iam.IPrincipal, sfnProps: StateMachineProps): DefinitionConfig; + +} + +export class FileDefinitionBody extends DefinitionBody { + + constructor(public readonly path: string, private readonly options: s3_assets.AssetOptions = { }) { + super(); + } + + public bind(scope: Construct, _sfnPrincipal: iam.IPrincipal, _sfnProps: StateMachineProps): DefinitionConfig { + const asset = new s3_assets.Asset(scope, 'DefinitionBody', { + path: this.path, + ...this.options, + }); + return { + definitionS3Location: { + bucket: asset.s3BucketName, + key: asset.s3ObjectKey, + }, + }; + } + +} + +export class StringDefinitionBody extends DefinitionBody { + + constructor(public readonly body: string) { + super(); + } + + public bind(_scope: Construct, _sfnPrincipal: iam.IPrincipal, _sfnProps: StateMachineProps): DefinitionConfig { + return { + definitionString: this.body, + }; + } +} + +export class ChainDefinitionBody extends DefinitionBody { + + constructor(public readonly chainable: IChainable) { + super(); + } + + public bind(scope: Construct, sfnPrincipal: iam.IPrincipal, sfnProps: StateMachineProps): DefinitionConfig { + const graph = new StateGraph(this.chainable.startState, 'State Machine definition'); + graph.timeout = sfnProps.timeout; + for (const statement of graph.policyStatements) { + sfnPrincipal.addToPrincipalPolicy(statement); + } + return { + definitionString: Stack.of(scope).toJsonString(graph.toGraphJson()), + }; + } + +} \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine-fragment.test.ts b/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine-fragment.test.ts index b3438a1693ff2..693b8781298e7 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine-fragment.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine-fragment.test.ts @@ -13,7 +13,7 @@ describe('State Machine Fragment', () => { const fragment2 = new ParallelMachineFragment(stack, 'Fragment 2').prefixStates(); new stepfunctions.StateMachine(stack, 'State Machine', { - definition: fragment1.next(fragment2), + definitionBody: stepfunctions.DefinitionBody.fromChainable(fragment1.next(fragment2)), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine-resources.test.ts b/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine-resources.test.ts index fb231ad43041a..0f9a268afe55e 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine-resources.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine-resources.test.ts @@ -24,7 +24,7 @@ describe('State Machine Resources', () => { // WHEN new stepfunctions.StateMachine(stack, 'SM', { - definition: task, + definitionBody: stepfunctions.DefinitionBody.fromChainable(task), }); // THEN @@ -59,7 +59,7 @@ describe('State Machine Resources', () => { // WHEN new stepfunctions.StateMachine(stack, 'SM', { - definition: para, + definitionBody: stepfunctions.DefinitionBody.fromChainable(para), }); // THEN @@ -107,13 +107,13 @@ describe('State Machine Resources', () => { Catch: undefined, InputPath: '$', Parameters: - { - 'input.$': '$', - 'stringArgument': 'inital-task', - 'numberArgument': 123, - 'booleanArgument': true, - 'arrayArgument': ['a', 'b', 'c'], - }, + { + 'input.$': '$', + 'stringArgument': 'inital-task', + 'numberArgument': 123, + 'booleanArgument': true, + 'arrayArgument': ['a', 'b', 'c'], + }, OutputPath: '$.state', Type: 'Task', Comment: undefined, @@ -153,10 +153,10 @@ describe('State Machine Resources', () => { Catch: undefined, InputPath: '$', Parameters: - { - a: 'aa', - b: 'bb', - }, + { + a: 'aa', + b: 'bb', + }, OutputPath: '$.state', Type: 'Task', Comment: undefined, @@ -172,7 +172,7 @@ describe('State Machine Resources', () => { const stack = new cdk.Stack(); const task = new FakeTask(stack, 'Task'); const stateMachine = new stepfunctions.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: stepfunctions.DefinitionBody.fromChainable(task), }); const role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), @@ -201,7 +201,7 @@ describe('State Machine Resources', () => { const stack = new cdk.Stack(); const task = new FakeTask(stack, 'Task'); const stateMachine = new stepfunctions.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: stepfunctions.DefinitionBody.fromChainable(task), stateMachineType: stepfunctions.StateMachineType.EXPRESS, }); const role = new iam.Role(stack, 'Role', { @@ -231,7 +231,7 @@ describe('State Machine Resources', () => { const stack = new cdk.Stack(); const task = new FakeTask(stack, 'Task'); const stateMachine = new stepfunctions.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: stepfunctions.DefinitionBody.fromChainable(task), }); const role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), @@ -317,7 +317,7 @@ describe('State Machine Resources', () => { const stack = new cdk.Stack(); const task = new FakeTask(stack, 'Task'); const stateMachine = new stepfunctions.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: stepfunctions.DefinitionBody.fromChainable(task), }); const role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), @@ -351,7 +351,7 @@ describe('State Machine Resources', () => { const stack = new cdk.Stack(); const task = new FakeTask(stack, 'Task'); const stateMachine = new stepfunctions.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: stepfunctions.DefinitionBody.fromChainable(task), }); const role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), @@ -412,7 +412,7 @@ describe('State Machine Resources', () => { const stack = new cdk.Stack(); const task = new FakeTask(stack, 'Task'); const stateMachine = new stepfunctions.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: stepfunctions.DefinitionBody.fromChainable(task), }); const role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), @@ -643,13 +643,13 @@ describe('State Machine Resources', () => { InputPath: '$', OutputPath: '$.state', Parameters: - { - 'input.$': '$', - 'stringArgument': 'inital-task', - 'numberArgument': 123, - 'booleanArgument': true, - 'arrayArgument': ['a', 'b', 'c'], - }, + { + 'input.$': '$', + 'stringArgument': 'inital-task', + 'numberArgument': 123, + 'booleanArgument': true, + 'arrayArgument': ['a', 'b', 'c'], + }, Type: 'Pass', Comment: undefined, Result: undefined, @@ -673,7 +673,7 @@ describe('State Machine Resources', () => { expect(taskState).toEqual({ End: true, Parameters: - { 'input.$': '$.myField' }, + { 'input.$': '$.myField' }, Type: 'Pass', }); }), @@ -690,7 +690,7 @@ describe('State Machine Resources', () => { ], }); new stepfunctions.StateMachine(stack, 'StateMachine', { - definition: task, + definitionBody: stepfunctions.DefinitionBody.fromChainable(task), }); // THEN diff --git a/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts b/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts index 87e8f09947839..4dd9b3c374dde 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts @@ -7,7 +7,7 @@ import * as cdk from '../../core'; import * as sfn from '../lib'; describe('State Machine', () => { - test('Instantiate Default State Machine', () => { + test('Instantiate Default State Machine with deprecated definition', () => { // GIVEN const stack = new cdk.Stack(); @@ -24,6 +24,66 @@ describe('State Machine', () => { }); }), + test('Instantiate Default State Machine with string definition', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + new sfn.StateMachine(stack, 'MyStateMachine', { + stateMachineName: 'MyStateMachine', + definitionBody: sfn.DefinitionBody.fromString('{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}'), + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', { + StateMachineName: 'MyStateMachine', + DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}', + }); + }), + + test('Instantiate fails with old and new definition specified', () => { + // GIVEN + const stack = new cdk.Stack(); + + // FAIL + expect(() => { + new sfn.StateMachine(stack, 'MyStateMachine', { + stateMachineName: 'MyStateMachine', + definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass2'))), + }); + }).toThrowError('Cannot specify definition and definitionBody at the same time'); + }), + + test('Instantiate fails with no definition specified', () => { + // GIVEN + const stack = new cdk.Stack(); + + // FAIL + expect(() => { + new sfn.StateMachine(stack, 'MyStateMachine', { + stateMachineName: 'MyStateMachine', + }); + }).toThrowError('You need to specify either definition or definitionBody'); + }), + + test('Instantiate Default State Machine', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + new sfn.StateMachine(stack, 'MyStateMachine', { + stateMachineName: 'MyStateMachine', + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))), + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', { + StateMachineName: 'MyStateMachine', + DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}', + }); + }), + test('Instantiate Standard State Machine', () => { // GIVEN const stack = new cdk.Stack(); @@ -31,7 +91,7 @@ describe('State Machine', () => { // WHEN new sfn.StateMachine(stack, 'MyStateMachine', { stateMachineName: 'MyStateMachine', - definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))), stateMachineType: sfn.StateMachineType.STANDARD, }); @@ -51,7 +111,7 @@ describe('State Machine', () => { // WHEN new sfn.StateMachine(stack, 'MyStateMachine', { stateMachineName: 'MyStateMachine', - definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))), stateMachineType: sfn.StateMachineType.EXPRESS, }); @@ -72,7 +132,7 @@ describe('State Machine', () => { const createStateMachine = (name: string) => { new sfn.StateMachine(stack, name + 'StateMachine', { stateMachineName: name, - definition: sfn.Chain.start(new sfn.Pass(stack, name + 'Pass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, name + 'Pass'))), stateMachineType: sfn.StateMachineType.EXPRESS, }); }; @@ -98,7 +158,7 @@ describe('State Machine', () => { // GIVEN const stack = new cdk.Stack(); const newStateMachine = new sfn.StateMachine(stack, 'dummyStateMachineToken', { - definition: sfn.Chain.start(new sfn.Pass(stack, 'dummyStateMachineTokenPass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'dummyStateMachineTokenPass'))), }); // WHEN @@ -109,7 +169,7 @@ describe('State Machine', () => { expect(() => { new sfn.StateMachine(stack, 'TokenTest-StateMachine', { stateMachineName: nameContainingToken, - definition: sfn.Chain.start(new sfn.Pass(stack, 'TokenTest-StateMachinePass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'TokenTest-StateMachinePass'))), stateMachineType: sfn.StateMachineType.EXPRESS, }); }).not.toThrow(); @@ -117,7 +177,7 @@ describe('State Machine', () => { expect(() => { new sfn.StateMachine(stack, 'ValidNameTest-StateMachine', { stateMachineName: validName, - definition: sfn.Chain.start(new sfn.Pass(stack, 'ValidNameTest-StateMachinePass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'ValidNameTest-StateMachinePass'))), stateMachineType: sfn.StateMachineType.EXPRESS, }); }).not.toThrow(); @@ -131,7 +191,7 @@ describe('State Machine', () => { const logGroup = new logs.LogGroup(stack, 'MyLogGroup'); new sfn.StateMachine(stack, 'MyStateMachine', { - definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))), logs: { destination: logGroup, level: sfn.LogLevel.FATAL, @@ -188,7 +248,7 @@ describe('State Machine', () => { // WHEN new sfn.StateMachine(stack, 'MyStateMachine', { - definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))), tracingEnabled: true, }); @@ -229,7 +289,7 @@ describe('State Machine', () => { // WHEN const sm = new sfn.StateMachine(stack, 'MyStateMachine', { - definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')), + definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))), }); const bucket = new s3.Bucket(stack, 'MyBucket'); bucket.grantRead(sm); @@ -289,7 +349,7 @@ describe('State Machine', () => { // WHEN new sfn.StateMachine(stateMachineStack, 'MyStateMachine', { - definition: new FakeTask(stateMachineStack, 'fakeTask', { credentials: { role: sfn.TaskRole.fromRole(role) } }), + definitionBody: sfn.DefinitionBody.fromChainable(new FakeTask(stateMachineStack, 'fakeTask', { credentials: { role: sfn.TaskRole.fromRole(role) } })), }); // THEN @@ -346,7 +406,7 @@ describe('State Machine', () => { // WHEN const role = iam.Role.fromRoleName(stack, 'Role', 'example-role'); new sfn.StateMachine(stack, 'MyStateMachine', { - definition: new FakeTask(stack, 'fakeTask', { credentials: { role: sfn.TaskRole.fromRole(role) } }), + definitionBody: sfn.DefinitionBody.fromChainable(new FakeTask(stack, 'fakeTask', { credentials: { role: sfn.TaskRole.fromRole(role) } })), }); // THEN @@ -410,7 +470,7 @@ describe('State Machine', () => { // WHEN new sfn.StateMachine(stack, 'MyStateMachine', { - definition: new FakeTask(stack, 'fakeTask', { credentials: { role: sfn.TaskRole.fromRoleArnJsonPath('$.RoleArn') } }), + definitionBody: sfn.DefinitionBody.fromChainable(new FakeTask(stack, 'fakeTask', { credentials: { role: sfn.TaskRole.fromRoleArnJsonPath('$.RoleArn') } })), }); // THEN @@ -510,7 +570,7 @@ describe('State Machine', () => { // WHEN new sfn.StateMachine(stack, 'MyStateMachine', { - definition: new sfn.Pass(stack, 'Pass'), + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Pass(stack, 'Pass')), removalPolicy: cdk.RemovalPolicy.RETAIN, }); diff --git a/packages/aws-cdk-lib/aws-stepfunctions/test/state.test.ts b/packages/aws-cdk-lib/aws-stepfunctions/test/state.test.ts index faaa2d8bf5115..bfa29d0fd032b 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions/test/state.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions/test/state.test.ts @@ -1,7 +1,7 @@ import { FakeTask } from './fake-task'; import * as assert from '../../assertions'; import * as cdk from '../../core'; -import { JsonPath, StateMachine } from '../lib'; +import { DefinitionBody, JsonPath, StateMachine } from '../lib'; test('JsonPath.DISCARD can be used to discard a state\'s output', () => { // GIVEN @@ -13,7 +13,7 @@ test('JsonPath.DISCARD can be used to discard a state\'s output', () => { resultPath: JsonPath.DISCARD, }); new StateMachine(stack, 'state-machine', { - definition: task, + definitionBody: DefinitionBody.fromChainable(task), }); // WHEN