@@ -12,7 +12,12 @@ module.exports = {
12
12
let DependsOn ;
13
13
14
14
if ( stateMachineObj . definition ) {
15
- DefinitionString = JSON . stringify ( stateMachineObj . definition ) ;
15
+ if ( typeof stateMachineObj . definition === 'string' ) {
16
+ DefinitionString = JSON . stringify ( stateMachineObj . definition )
17
+ . replace ( / \\ n | \\ r | \\ n \\ r / g, '' ) ;
18
+ } else {
19
+ DefinitionString = JSON . stringify ( stateMachineObj . definition , undefined , 2 ) ;
20
+ }
16
21
} else {
17
22
const errorMessage = [
18
23
`Missing "definition" property in stateMachine ${ stateMachineName } ` ,
@@ -25,7 +30,7 @@ module.exports = {
25
30
if ( stateMachineObj . role ) {
26
31
if ( typeof stateMachineObj . role === 'string' ) {
27
32
if ( stateMachineObj . role . startsWith ( 'arn:aws' ) ) {
28
- RoleArn = `" ${ stateMachineObj . role } "` ;
33
+ RoleArn = stateMachineObj . role ;
29
34
} else {
30
35
const errorMessage = [
31
36
`role property in stateMachine "${ stateMachineName } " is not ARN` ,
@@ -43,29 +48,31 @@ module.exports = {
43
48
. Error ( errorMessage ) ;
44
49
}
45
50
} else {
46
- RoleArn = '{ "Fn::GetAtt": ["IamRoleStateMachineExecution", "Arn"] }' ;
51
+ RoleArn = {
52
+ 'Fn::GetAtt' : [
53
+ 'IamRoleStateMachineExecution' ,
54
+ 'Arn' ,
55
+ ] ,
56
+ } ;
47
57
DependsOn = 'IamRoleStateMachineExecution' ;
48
58
}
49
59
50
60
const stateMachineLogicalId = this . getStateMachineLogicalId ( stateMachineName ,
51
61
stateMachineObj ) ;
52
62
const stateMachineOutputLogicalId = this
53
- . getStateMachineOutputLogicalId ( stateMachineName , stateMachineObj ) ;
54
-
55
- const stateMachineTemplate = `
63
+ . getStateMachineOutputLogicalId ( stateMachineName , stateMachineObj ) ;
64
+ const stateMachineTemplate =
56
65
{
57
- "Type": "AWS::StepFunctions::StateMachine",
58
- "Properties": {
59
- "DefinitionString": ${ JSON . stringify ( DefinitionString
60
- . replace ( / \\ n | \\ r | \\ n \\ r / g, '' ) ) } ,
61
- "RoleArn": ${ RoleArn }
62
- }
63
- ${ DependsOn ? `,"DependsOn": "${ DependsOn } "` : '' }
64
- }
65
- ` ;
66
+ Type : 'AWS::StepFunctions::StateMachine' ,
67
+ Properties : {
68
+ DefinitionString,
69
+ RoleArn,
70
+ } ,
71
+ DependsOn,
72
+ } ;
66
73
67
74
const newStateMachineObject = {
68
- [ stateMachineLogicalId ] : JSON . parse ( stateMachineTemplate ) ,
75
+ [ stateMachineLogicalId ] : stateMachineTemplate ,
69
76
} ;
70
77
71
78
if ( stateMachineObj . name ) {
0 commit comments