serverless-step-functions
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -13,3 +13,8 @@ 'use strict'; | ||
let DependsOn; | ||
let Name; | ||
if (stateMachineObj.name) { | ||
Name = stateMachineObj.name; | ||
} | ||
if (stateMachineObj.definition) { | ||
@@ -51,4 +56,5 @@ DefinitionString = JSON.stringify(stateMachineObj.definition); | ||
const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName); | ||
const stateMachineOutputLogicalId = this.getStateMachineOutputLogicalId(stateMachineName); | ||
const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName, Name); | ||
const stateMachineOutputLogicalId = this | ||
.getStateMachineOutputLogicalId(stateMachineName, Name); | ||
@@ -88,2 +94,3 @@ const stateMachineTemplate = ` | ||
); | ||
return BbPromise.resolve(); | ||
@@ -90,0 +97,0 @@ }); |
@@ -79,2 +79,51 @@ 'use strict'; | ||
it('should create named resources when Name is provided', () => { | ||
serverless.service.stepFunctions = { | ||
stateMachines: { | ||
myStateMachine1: { | ||
definition: 'definition1', | ||
name: 'stateMachineBeta1', | ||
}, | ||
myStateMachine2: { | ||
definition: 'definition2', | ||
name: 'stateMachineBeta2', | ||
}, | ||
}, | ||
}; | ||
serverlessStepFunctions.compileStateMachines(); | ||
expect(serverlessStepFunctions.serverless.service | ||
.provider.compiledCloudFormationTemplate.Resources | ||
.StateMachineBeta1.Type | ||
).to.equal('AWS::StepFunctions::StateMachine'); | ||
expect(serverlessStepFunctions.serverless.service | ||
.provider.compiledCloudFormationTemplate.Resources | ||
.StateMachineBeta2.Type | ||
).to.equal('AWS::StepFunctions::StateMachine'); | ||
expect(serverlessStepFunctions.serverless.service | ||
.provider.compiledCloudFormationTemplate.Resources | ||
.StateMachineBeta1.Properties.DefinitionString | ||
).to.equal('"definition1"'); | ||
expect(serverlessStepFunctions.serverless.service | ||
.provider.compiledCloudFormationTemplate.Resources | ||
.StateMachineBeta2.Properties.DefinitionString | ||
).to.equal('"definition2"'); | ||
expect(serverlessStepFunctions.serverless.service | ||
.provider.compiledCloudFormationTemplate.Resources | ||
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0] | ||
).to.equal('IamRoleStateMachineExecution'); | ||
expect(serverlessStepFunctions.serverless.service | ||
.provider.compiledCloudFormationTemplate.Resources | ||
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0] | ||
).to.equal('IamRoleStateMachineExecution'); | ||
expect(serverlessStepFunctions.serverless.service | ||
.provider.compiledCloudFormationTemplate.Resources | ||
.StateMachineBeta1.DependsOn | ||
).to.equal('IamRoleStateMachineExecution'); | ||
expect(serverlessStepFunctions.serverless.service | ||
.provider.compiledCloudFormationTemplate.Resources | ||
.StateMachineBeta2.DependsOn | ||
).to.equal('IamRoleStateMachineExecution'); | ||
}); | ||
it('should create corresponding resources when definition and role property are given', () => { | ||
@@ -81,0 +130,0 @@ serverless.service.stepFunctions = { |
@@ -86,9 +86,9 @@ 'use strict'; | ||
.then(this.invoke), | ||
'deploy:initialize': () => BbPromise.bind(this) | ||
'package:initialize': () => BbPromise.bind(this) | ||
.then(this.yamlParse), | ||
'deploy:compileFunctions': () => BbPromise.bind(this) | ||
'package:compileFunctions': () => BbPromise.bind(this) | ||
.then(this.compileIamRole) | ||
.then(this.compileStateMachines) | ||
.then(this.compileActivities), | ||
'deploy:compileEvents': () => { | ||
'package:compileEvents': () => { | ||
this.pluginhttpValidated = this.httpValidate(); | ||
@@ -164,4 +164,5 @@ | ||
this.serverless.cli.consoleLog(message); | ||
return message; | ||
} | ||
} | ||
module.exports = ServerlessStepFunctions; |
@@ -11,2 +11,3 @@ 'use strict'; | ||
const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider'); | ||
const CLI = require('serverless/lib/classes/CLI'); | ||
const ServerlessStepFunctions = require('./../index'); | ||
@@ -21,2 +22,3 @@ | ||
serverless.setProvider('aws', new AwsProvider(serverless)); | ||
serverless.cli = new CLI(serverless); | ||
serverless.service.service = 'new-service'; | ||
@@ -23,0 +25,0 @@ const options = { |
'use strict'; | ||
module.exports = { | ||
getStateMachineLogicalId(stateMachineName) { | ||
getStateMachineLogicalId(stateMachineName, customName) { | ||
if (customName) { | ||
return `${this.provider.naming.getNormalizedFunctionName(customName)}`; | ||
} | ||
return `${this.provider.naming | ||
@@ -9,3 +12,6 @@ .getNormalizedFunctionName(stateMachineName)}StepFunctionsStateMachine`; | ||
getStateMachineOutputLogicalId(stateMachineName) { | ||
getStateMachineOutputLogicalId(stateMachineName, customName) { | ||
if (customName) { | ||
return `${this.provider.naming.getNormalizedFunctionName(customName)}Arn`; | ||
} | ||
return `${this.provider.naming | ||
@@ -12,0 +18,0 @@ .getNormalizedFunctionName(stateMachineName)}StepFunctionsStateMachineArn`; |
@@ -35,2 +35,16 @@ 'use strict'; | ||
describe('#getStateMachineLogicalId() -- Named', () => { | ||
it('should normalize the stateMachine name and add the standard suffix', () => { | ||
expect(serverlessStepFunctions.getStateMachineLogicalId('stateMachine', 'alphaNumeric')).to | ||
.equal('AlphaNumeric'); | ||
}); | ||
}); | ||
describe('#getStateMachineOutputLogicalId() -- Named', () => { | ||
it('should normalize the stateMachine output name and add the standard suffix', () => { | ||
expect(serverlessStepFunctions.getStateMachineOutputLogicalId('stateMachine', 'alphaNumeric')) | ||
.to.equal('AlphaNumericArn'); | ||
}); | ||
}); | ||
describe('#getActivityLogicalId()', () => { | ||
@@ -37,0 +51,0 @@ it('should normalize the activity name and add the standard suffix', () => { |
{ | ||
"name": "serverless-step-functions", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "The module is AWS Step Functions plugin for Serverless Framework", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -37,2 +37,3 @@ [![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) [![Build Status](https://travis-ci.org/horike37/serverless-step-functions.svg?branch=master)](https://travis-ci.org/horike37/serverless-step-functions) [![npm version](https://badge.fury.io/js/serverless-step-functions.svg)](https://badge.fury.io/js/serverless-step-functions) [![Coverage Status](https://coveralls.io/repos/github/horike37/serverless-step-functions/badge.svg?branch=master)](https://coveralls.io/github/horike37/serverless-step-functions?branch=master) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) | ||
method: GET | ||
name: myStateMachine | ||
definition: | ||
@@ -59,2 +60,27 @@ Comment: "A Hello World example of the Amazon States Language using an AWS Lambda Function" | ||
### 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 | ||
@@ -130,1 +156,30 @@ ### API Gateway | ||
``` | ||
## Tips | ||
### How to specify the stateMachine ARN to environment variables | ||
Here is serverless.yml sample to specify the stateMachine ARN to environment variables. | ||
This makes it possible to trigger your statemachine through Lambda events | ||
```yml | ||
functions: | ||
hello: | ||
handler: handler.hello | ||
environment: | ||
statemachine_arn: ${self:resources.Outputs.MyStateMachine.Value} | ||
stepFunctions: | ||
stateMachines: | ||
hellostepfunc: | ||
name: myStateMachine | ||
definition: | ||
<your definition> | ||
resources: | ||
Outputs: | ||
MyStateMachine: | ||
Description: The ARN of the example state machine | ||
Value: | ||
Ref: MyStateMachine | ||
plugins: | ||
- serverless-step-functions | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118886
39
2956
183