diff --git a/README.md b/README.md index 4acba9c9..038eb2b0 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ stepFunctions: - http: path: gofunction method: GET + name: myStateMachine definition: Comment: "A Hello World example of the Amazon States Language using an AWS Lambda Function" StartAt: HelloWorld1 @@ -55,6 +56,31 @@ stepFunctions: - yourTask ``` +### Adding a custom name for a stateMachine +In case you need to interpolate a specific stage or service layer variable as the +stateMachines name you can add a `name` property to your yaml. + +```yml +service: messager + +functions: + sendMessage: + handler: handler.sendMessage + +stepFunctions: + stateMachines: + sendMessageFunc: + name: sendMessageFunc-${self:custom.service}-${opt:stage} + definition: + + +plugins: + - serverless-step-functions +``` + +Please note, that during normalization some characters will be changed to adhere to CloudFormation templates. +You can get the real statemachine name using `{ "Fn::GetAtt": ["MyStateMachine", "Name"] }`. + ## Events ### API Gateway To create HTTP endpoints as Event sources for your StepFunctions statemachine @@ -135,45 +161,22 @@ functions: hello: handler: handler.hello environment: - statemachine_arn: ${self:resources.Outputs.HelloStepfunc.Value} + statemachine_arn: ${self:resources.Outputs.MyStateMachine.Value} stepFunctions: stateMachines: hellostepfunc: + name: myStateMachine definition: resources: Outputs: - HelloStepfunc: + MyStateMachine: Description: The ARN of the example state machine Value: - Ref: HellostepfuncStepFunctionsStateMachine + Ref: MyStateMachine plugins: - serverless-step-functions ``` - -### Adding a custom name for a stateMachine -In case you need to interpolate a specific stage or service layer variable as the -stateMachines name you can add a `Name` property to your yaml. - -```yml -service: messager - -functions: - sendMessage: - handler: handler.sendMessage - -stepFunctions: - stateMachines: - sendMessageFunc: - Name: sendMessageFunc-${self:custom.service}-${opt:stage} - definition: - - -plugins: - - serverless-step-functions -``` - -Please note, that during normalization some characters will be changed to adhere to CloudFormation templates. diff --git a/lib/deploy/stepFunctions/compileStateMachines.js b/lib/deploy/stepFunctions/compileStateMachines.js index f2ddd337..f34e57b6 100644 --- a/lib/deploy/stepFunctions/compileStateMachines.js +++ b/lib/deploy/stepFunctions/compileStateMachines.js @@ -12,8 +12,8 @@ module.exports = { let DependsOn; let Name; - if (stateMachineObj.Name) { - Name = stateMachineObj.Name; + if (stateMachineObj.name) { + Name = stateMachineObj.name; } if (stateMachineObj.definition) { diff --git a/lib/deploy/stepFunctions/compileStateMachines.test.js b/lib/deploy/stepFunctions/compileStateMachines.test.js index d5c4c368..ad6781aa 100644 --- a/lib/deploy/stepFunctions/compileStateMachines.test.js +++ b/lib/deploy/stepFunctions/compileStateMachines.test.js @@ -81,11 +81,11 @@ describe('#compileStateMachines', () => { stateMachines: { myStateMachine1: { definition: 'definition1', - Name: 'stateMachineBeta1', + name: 'stateMachineBeta1', }, myStateMachine2: { definition: 'definition2', - Name: 'stateMachineBeta2', + name: 'stateMachineBeta2', }, }, }; diff --git a/lib/naming.js b/lib/naming.js index b4817e81..a4e3b114 100644 --- a/lib/naming.js +++ b/lib/naming.js @@ -1,17 +1,17 @@ 'use strict'; module.exports = { - getStateMachineLogicalId(stateMachineName, Name) { - if (Name) { - return `${this.provider.naming.getNormalizedFunctionName(Name)}`; + getStateMachineLogicalId(stateMachineName, customName) { + if (customName) { + return `${this.provider.naming.getNormalizedFunctionName(customName)}`; } return `${this.provider.naming .getNormalizedFunctionName(stateMachineName)}StepFunctionsStateMachine`; }, - getStateMachineOutputLogicalId(stateMachineName, Name) { - if (Name) { - return `${this.provider.naming.getNormalizedFunctionName(Name)}Arn`; + getStateMachineOutputLogicalId(stateMachineName, customName) { + if (customName) { + return `${this.provider.naming.getNormalizedFunctionName(customName)}Arn`; } return `${this.provider.naming .getNormalizedFunctionName(stateMachineName)}StepFunctionsStateMachineArn`;