Skip to content

Commit

Permalink
update name variables to follow camelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
horike37 committed Jun 12, 2017
1 parent 18aba0f commit 70f4d69
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
57 changes: 30 additions & 27 deletions README.md
Expand Up @@ -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
Expand All @@ -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:
<your 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
Expand Down Expand Up @@ -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:
<your 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:
<your definition>

plugins:
- serverless-step-functions
```

Please note, that during normalization some characters will be changed to adhere to CloudFormation templates.
4 changes: 2 additions & 2 deletions lib/deploy/stepFunctions/compileStateMachines.js
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/deploy/stepFunctions/compileStateMachines.test.js
Expand Up @@ -81,11 +81,11 @@ describe('#compileStateMachines', () => {
stateMachines: {
myStateMachine1: {
definition: 'definition1',
Name: 'stateMachineBeta1',
name: 'stateMachineBeta1',
},
myStateMachine2: {
definition: 'definition2',
Name: 'stateMachineBeta2',
name: 'stateMachineBeta2',
},
},
};
Expand Down
12 changes: 6 additions & 6 deletions 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`;
Expand Down

0 comments on commit 70f4d69

Please sign in to comment.