@@ -8,11 +8,13 @@ class ServerlessStepFunctions {
88 this . serverless = serverless ;
99 this . options = options || { } ;
1010 this . provider = this . serverless . getProvider ( 'aws' ) ;
11+ this . service = this . serverless . service . service ;
12+ this . region = this . provider . getRegion ( ) ;
13+ this . stage = this . provider . getStage ( ) ;
1114 this . awsStateLanguage = { } ;
1215 this . functionArns = { } ;
13- const region = this . options . region || 'us-east-1' ;
14- this . iamRoleName = `serverless-step-functions-executerole-${ region } ` ;
15- this . iamPolicyName = `serverless-step-functions-executepolicy-${ region } ` ;
16+ this . iamRoleName = `serverless-step-functions-executerole-${ this . region } ` ;
17+ this . iamPolicyName = `serverless-step-functions-executepolicy-${ this . region } ` ;
1618 this . iamPolicyStatement = `{
1719 "Version": "2012-10-17",
1820 "Statement": [
@@ -33,7 +35,7 @@ class ServerlessStepFunctions {
3335 {
3436 "Effect": "Allow",
3537 "Principal": {
36- "Service": "states.${ region } .amazonaws.com"
38+ "Service": "states.${ this . region } .amazonaws.com"
3739 },
3840 "Action": "sts:AssumeRole"
3941 }
@@ -55,6 +57,14 @@ class ServerlessStepFunctions {
5557 shortcut : 't' ,
5658 required : true ,
5759 } ,
60+ stage : {
61+ usage : 'Stage of the service' ,
62+ shortcut : 's' ,
63+ } ,
64+ region : {
65+ usage : 'Region of the service' ,
66+ shortcut : 'r' ,
67+ } ,
5868 } ,
5969 } ,
6070 } ,
@@ -72,6 +82,14 @@ class ServerlessStepFunctions {
7282 shortcut : 't' ,
7383 required : true ,
7484 } ,
85+ stage : {
86+ usage : 'Stage of the service' ,
87+ shortcut : 's' ,
88+ } ,
89+ region : {
90+ usage : 'Region of the service' ,
91+ shortcut : 'r' ,
92+ } ,
7593 } ,
7694 } ,
7795 } ,
@@ -93,6 +111,14 @@ class ServerlessStepFunctions {
93111 usage : 'String data to be passed as an event to your step function' ,
94112 shortcut : 'd' ,
95113 } ,
114+ stage : {
115+ usage : 'Stage of the service' ,
116+ shortcut : 's' ,
117+ } ,
118+ region : {
119+ usage : 'Region of the service' ,
120+ shortcut : 'r' ,
121+ } ,
96122 } ,
97123 } ,
98124 } ,
@@ -138,6 +164,10 @@ class ServerlessStepFunctions {
138164 . then ( this . describeExecution ) ;
139165 }
140166
167+ getStateMachineName ( ) {
168+ return `${ this . service } -${ this . stage } -${ this . options . state } ` ;
169+ }
170+
141171 getIamRole ( ) {
142172 return this . provider . request ( 'IAM' ,
143173 'getRole' ,
@@ -164,10 +194,9 @@ class ServerlessStepFunctions {
164194 this . options . stage ,
165195 this . options . region )
166196 . then ( ( result ) => {
167- const region = this . options . region || 'us-east-1' ;
168197 _ . forEach ( this . serverless . service . functions , ( value , key ) => {
169198 this . functionArns [ key ]
170- = `arn:aws:lambda:${ region } :${ result . Account } :function:${ value . name } ` ;
199+ = `arn:aws:lambda:${ this . region } :${ result . Account } :function:${ value . name } ` ;
171200 } ) ;
172201 return BbPromise . resolve ( ) ;
173202 } ) ;
@@ -212,10 +241,8 @@ class ServerlessStepFunctions {
212241 this . options . stage ,
213242 this . options . region )
214243 . then ( ( result ) => {
215- const region = this . options . region || 'us-east-1' ;
216- const stage = this . options . stage || 'dev' ;
217244 this . stateMachineArn =
218- `arn:aws:states:${ region } :${ result . Account } :stateMachine:${ this . options . state } - ${ stage } ` ;
245+ `arn:aws:states:${ this . region } :${ result . Account } :stateMachine:${ this . getStateMachineName ( ) } ` ;
219246 return BbPromise . resolve ( ) ;
220247 } ) ;
221248 }
@@ -232,19 +259,18 @@ class ServerlessStepFunctions {
232259 }
233260
234261 createStateMachine ( ) {
235- const stage = this . options . stage || 'dev' ;
236262 return this . provider . request ( 'StepFunctions' ,
237263 'createStateMachine' ,
238264 {
239265 definition : this . awsStateLanguage [ this . options . state ] ,
240- name : ` ${ this . options . state } - ${ stage } ` ,
266+ name : this . getStateMachineName ( ) ,
241267 roleArn : this . iamRoleArn ,
242268 } ,
243269 this . options . stage ,
244270 this . options . region )
245271 . then ( ( ) => {
246272 this . serverless . cli . consoleLog ( '' ) ;
247- this . serverless . cli . log ( `Finish to deploy ${ this . options . state } - ${ stage } step function` ) ;
273+ this . serverless . cli . log ( `Finish to deploy ${ this . getStateMachineName ( ) } step function` ) ;
248274 return BbPromise . resolve ( ) ;
249275 } ) . catch ( ( error ) => {
250276 if ( error . message . match ( / S t a t e M a c h i n e i s b e i n g d e l e t e d / ) ) {
0 commit comments