Skip to content
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

feat(stepfunctions): support string and file definitions #25508

Closed
wants to merge 14 commits into from
Original file line number Diff line number Diff line change
@@ -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 <stack-output> 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();
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand Down Expand Up @@ -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);
Expand All @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
});

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('Start Query Execution', () => {
});

new sfn.StateMachine(stack, 'StateMachine', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('CallAwsService task', () => {
});

new sfn.StateMachine(stack, 'StateMachine', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down Expand Up @@ -73,7 +73,7 @@ test('with custom IAM action', () => {
});

new sfn.StateMachine(stack, 'StateMachine', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down Expand Up @@ -118,7 +118,7 @@ test('with unresolved tokens', () => {
});

new sfn.StateMachine(stack, 'StateMachine', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down Expand Up @@ -176,7 +176,7 @@ test('can pass additional IAM statements', () => {
});

new sfn.StateMachine(stack, 'StateMachine', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down Expand Up @@ -212,7 +212,7 @@ test('IAM policy for sfn', () => {
});

new sfn.StateMachine(stack, 'StateMachine', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describeDeprecated('ecs-tasks', () => {
});

new sfn.StateMachine(stack, 'SM', {
definition: runTask,
definitionBody: sfn.DefinitionBody.fromChainable(runTask),
});

// THEN
Expand Down Expand Up @@ -191,7 +191,7 @@ describeDeprecated('ecs-tasks', () => {
});

new sfn.StateMachine(stack, 'SM', {
definition: runTask,
definitionBody: sfn.DefinitionBody.fromChainable(runTask),
});

// THEN
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -235,7 +235,7 @@ test('Running a Fargate Task', () => {
});

new sfn.StateMachine(stack, 'SM', {
definition: runTask,
definitionBody: sfn.DefinitionBody.fromChainable(runTask),
});

// THEN
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('task policies are generated', () => {
stepId: 'StepId',
});
new sfn.StateMachine(stack, 'SM', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test('task policies are generated', () => {
targetSpotCapacity: 0,
});
new sfn.StateMachine(stack, 'SM', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test('task policies are generated', () => {
},
});
new sfn.StateMachine(stack, 'SM', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('task policies are generated', () => {
terminationProtected: false,
});
new sfn.StateMachine(stack, 'SM', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
});

new sfn.StateMachine(stack, 'SM', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
});

new sfn.StateMachine(stack, 'SM', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
});

new sfn.StateMachine(stack, 'SM', {
definition: task,
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
Expand All @@ -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
Expand Down
Loading