Skip to content

Commit

Permalink
Merge pull request #31 from mbonig/fix/definition-deprecation
Browse files Browse the repository at this point in the history
fix: updating to 2.85.0 of the CDK and updating usages
  • Loading branch information
mbonig authored Oct 19, 2023
2 parents c1b83c8 + 20efe2c commit 24ecf64
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
author: 'Matthew Bonig',
authorAddress: 'matthew.bonig@gmail.com',
description: 'A Step Function state machine construct focused on working well with the Workflow Studio',
cdkVersion: '2.53.0',
cdkVersion: '2.85.0',
defaultReleaseBranch: 'main',
constructsVersion: '10.1.203',
name: '@matthewbonig/state-machine',
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Create a new instance of this construct, handing it a fully parsed version of th
Then add overridden values.
The fields in the `overrides` field should match the `States` field of the ASL.

## Version Usage

The AWS CDK StateMachine construct introduced a change in version [**2.85.0**](https://github.com/aws/aws-cdk/pull/25932) that deprecated an earlier usage of 'definition'
by this construct. This construct has been updated to use the new 'definitionBody' field.

If you are using a version of the CDK before version **2.85.0**, you should use version **0.0.28** of this construct.

If you are using a version fo the CDK great or equal to **2.85.0**, you should use version **0.0.29+** of this construct.

### Projen component

There is a projen component included in this library which will help you in using the construct. It works similar
Expand Down
4 changes: 2 additions & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions src/StateMachine.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Duration } from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as aws_stepfunctions from 'aws-cdk-lib/aws-stepfunctions';
import { CfnStateMachine, LogOptions, Pass, StateMachineType } from 'aws-cdk-lib/aws-stepfunctions';
import { DefinitionBody, LogOptions, StateMachineType } from 'aws-cdk-lib/aws-stepfunctions';
import { Construct } from 'constructs';
import * as yaml from 'js-yaml';

Expand Down Expand Up @@ -76,20 +76,21 @@ export interface StateMachineProps {
export class StateMachine extends aws_stepfunctions.StateMachine {

constructor(scope: Construct, id: string, props: StateMachineProps) {
super(scope, id, {
...props,
definition: new Pass(scope, 'THISWILLBEDELETEDRIGHTAWAY'),
});
scope.node.tryRemoveChild('THISWILLBEDELETEDRIGHTAWAY');
const mergedDefinition = merge(props.definition, { States: props.overrides });
let definitionString: string;
if (props.aslYaml) {
definitionString = yaml.dump(mergedDefinition);
} else {
definitionString = JSON.stringify(mergedDefinition);

}
(this.node.defaultChild as CfnStateMachine).definitionString = definitionString;
const propsMinusDefinition = {
...props,
definition: undefined,
};
super(scope, id, {
...propsMinusDefinition,
definitionBody: DefinitionBody.fromString(definitionString),
});
}
}

8 changes: 8 additions & 0 deletions test/__snapshots__/StateMachine.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 65 additions & 40 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24ecf64

Please sign in to comment.