11'use strict' ;
22const BbPromise = require ( 'bluebird' ) ;
33const path = require ( 'path' ) ;
4+ const _ = require ( 'lodash' ) ;
45
56class AwsStepFunctionsDeploy {
67 constructor ( serverless , options ) {
78 this . serverless = serverless ;
89 this . options = options ;
910 this . provider = this . serverless . getProvider ( 'aws' ) ;
1011 this . awsStateLanguage = { } ;
12+ this . functionArns = { } ;
1113 this . commands = {
1214 deploy : {
1315 commands : {
@@ -52,7 +54,8 @@ class AwsStepFunctionsDeploy {
5254 this . serverless . cli . consoleLog ( 'Start Deploy Step Functions' ) ;
5355 BbPromise . bind ( this )
5456 . then ( this . yamlParse )
55- . then ( this . setStateMachineArn )
57+ . then ( this . getStateMachineArn )
58+ . then ( this . getFunctionArns )
5659 . then ( this . compile )
5760 . then ( this . getIamRole )
5861 . then ( this . deleteStateMachine )
@@ -78,6 +81,22 @@ class AwsStepFunctionsDeploy {
7881 } ) ;
7982 }
8083
84+ getFunctionArns ( ) {
85+ return this . provider . request ( 'STS' ,
86+ 'getCallerIdentity' ,
87+ { } ,
88+ this . options . stage ,
89+ this . options . region )
90+ . then ( ( result ) => {
91+ const region = this . options . region || 'us-east-1' ;
92+ _ . forEach ( this . serverless . service . functions , ( value , key ) => {
93+ this . functionArns [ key ]
94+ = `arn:aws:lambda:${ region } :${ result . Account } :function:${ value . name } ` ;
95+ } ) ;
96+ return BbPromise . resolve ( ) ;
97+ } ) ;
98+ }
99+
81100 createIamRole ( ) {
82101 return this . provider . request ( 'IAM' ,
83102 'createRole' ,
@@ -93,7 +112,7 @@ class AwsStepFunctionsDeploy {
93112 } ) ;
94113 }
95114
96- setStateMachineArn ( ) {
115+ getStateMachineArn ( ) {
97116 return this . provider . request ( 'STS' ,
98117 'getCallerIdentity' ,
99118 { } ,
@@ -140,6 +159,13 @@ class AwsStepFunctionsDeploy {
140159 throw new this . serverless . classes . Error ( errorMessage ) ;
141160 }
142161
162+ _ . forEach ( this . stepFunctions [ this . options . statemachine ] . States , ( value , key ) => {
163+ if ( value . Resource && ! value . Resource . match ( / a r n : a w s : l a m b d a / ) ) {
164+ this . stepFunctions [ this . options . statemachine ] . States [ key ] . Resource
165+ = this . functionArns [ value . Resource ] ;
166+ }
167+ } ) ;
168+
143169 this . awsStateLanguage [ this . options . statemachine ] =
144170 JSON . stringify ( this . stepFunctions [ this . options . statemachine ] ) ;
145171 return BbPromise . resolve ( ) ;
@@ -173,12 +199,5 @@ class AwsStepFunctionsDeploy {
173199 }
174200 } ) ;
175201 }
176-
177- deploy ( ) {
178- return BbPromise . bind ( this )
179- . then ( this . deleteStateMachine )
180- . then ( this . createStateMachine ) ;
181- }
182-
183202}
184203module . exports = AwsStepFunctionsDeploy ;
0 commit comments