@@ -107,22 +107,9 @@ class ServerlessStepFunctionsLocal {
107107 const preParsed = await this . serverless . yamlParser . parse ( configPath ) ;
108108 const parsed = await this . serverless . variables . populateObject ( preParsed ) ;
109109
110- this . stateMachines = parsed . stepFunctions . stateMachines ;
111-
112- // replace Fn::GetAtt
113- Object . keys ( this . stateMachines ) . map ( stateMachineName => {
114- const machine = this . stateMachines [ stateMachineName ]
115- Object . keys ( machine . definition . States ) . map ( stateName => {
116- const state = machine . definition . States [ stateName ]
117- if ( state . Type === 'Task' ) {
118- if ( state . Resource && state . Resource [ 'Fn::GetAtt' ] && Array . isArray ( state . Resource [ 'Fn::GetAtt' ] ) ) {
119- state . Resource = `arn:aws:lambda:${ this . config . region } :${ this . config . accountId } :function:${ this . service . service } -${ this . serverless . stage ? this . serverless . stage : 'dev' } -${ state . Resource [ 'Fn::GetAtt' ] [ 0 ] } `
120- }
121- }
122- } )
123- } )
124-
125- if ( parsed . custom
110+ this . stateMachines = this . stateMachineCFARNResolver ( parsed . stepFunctions . stateMachines ) ;
111+
112+ if ( parsed . custom
126113 && parsed . custom . stepFunctionsLocal
127114 && parsed . custom . stepFunctionsLocal . TaskResourceMapping ) {
128115 this . replaceTaskResourceMappings ( parsed . stepFunctions . stateMachines , parsed . custom . stepFunctionsLocal . TaskResourceMapping ) ;
@@ -160,30 +147,30 @@ class ServerlessStepFunctionsLocal {
160147 const data = await this . stepfunctionsAPI . listStateMachines ( {
161148 nextToken : ( nextToken === EMPTY ? undefined : nextToken )
162149 } ) . promise ( )
163-
150+
164151 nextToken = data . nextToken
165152 for ( const machine of data . stateMachines ) {
166- if ( ! knownStateMachines . includes ( machine . name ) ) {
153+ if ( ! knownStateMachines . includes ( machine . name ) ) {
167154 continue
168155 }
169156 hasRunningMachine = true
170-
157+
171158 await this . stepfunctionsAPI . deleteStateMachine ( {
172159 stateMachineArn : machine . stateMachineArn
173160 } )
174- . promise ( )
175- . catch ( err => {
176- // state machine was not found
177- if ( err && err . code === 400 ) {
178- return
179- }
180-
181- throw err
182- } )
161+ . promise ( )
162+ . catch ( err => {
163+ // state machine was not found
164+ if ( err && err . code === 400 ) {
165+ return
166+ }
167+
168+ throw err
169+ } )
183170 }
184171 }
185172
186- if ( ! hasRunningMachine ) {
173+ if ( ! hasRunningMachine ) {
187174 break
188175 }
189176
@@ -203,6 +190,49 @@ class ServerlessStepFunctionsLocal {
203190 process . env [ `OFFLINE_STEP_FUNCTIONS_ARN_${ endpoint . stateMachineArn . split ( ':' ) [ 6 ] } ` ] = endpoint . stateMachineArn ;
204191 } ) ;
205192 }
193+
194+ /**
195+ * Pure Function that will parse Fn:GetAtt and !GetAtt CloudFormation functions from state machine
196+ */
197+ stateMachineCFARNResolver ( stateMachines ) {
198+ const newStateMachines = { ...stateMachines }
199+
200+ for ( const [ stateMachineName , stateMachine ] of Object . entries ( newStateMachines ) ) {
201+ stateMachine . definition . States = this . statesCFARNResolver ( stateMachine . definition . States ) ;
202+ }
203+
204+ return newStateMachines ;
205+ }
206+
207+ /**
208+ * Pure Function that will parse Fn:GetAtt and !GetAtt CloudFormation functions from States
209+ */
210+ statesCFARNResolver ( states ) {
211+ const newStates = { ...states }
212+
213+ for ( const [ stateName , state ] of Object . entries ( newStates ) ) {
214+ switch ( state . Type ) {
215+ case 'Task' :
216+ if ( state . Resource && state . Resource [ 'Fn::GetAtt' ] && Array . isArray ( state . Resource [ 'Fn::GetAtt' ] ) ) {
217+ state . Resource = `arn:aws:lambda:${ this . config . region } :${ this . config . accountId } :function:${ this . service . service } -${ this . serverless . stage ? this . serverless . stage : 'dev' } -${ state . Resource [ 'Fn::GetAtt' ] [ 0 ] } `
218+ }
219+ break ;
220+ case 'Map' :
221+ state . Iterator . States = this . statesCFARNResolver ( state . Iterator . States ) ;
222+ break ;
223+ case 'Parallel' :
224+ for ( const branch of state . Branches ) {
225+ branch . States = this . statesCFARNResolver ( branch . States ) ;
226+ }
227+ break ;
228+ default :
229+ // ignore
230+ break ;
231+ }
232+ }
233+
234+ return newStates ;
235+ }
206236}
207237
208238module . exports = ServerlessStepFunctionsLocal ;
0 commit comments