serverless-step-functions
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -19,3 +19,7 @@ 'use strict'; | ||
.then((serverlessFileParam) => { | ||
this.serverless.service.stepFunctions = serverlessFileParam.stepFunctions.stateMachines; | ||
this.serverless.service.stepFunctions = {}; | ||
this.serverless.service.stepFunctions.stateMachines | ||
= serverlessFileParam.stepFunctions.stateMachines; | ||
this.serverless.service.stepFunctions.activities | ||
= serverlessFileParam.stepFunctions.activities; | ||
this.serverless.variables.populateService(this.serverless.pluginManager.cliOptions); | ||
@@ -55,3 +59,3 @@ return BbPromise.resolve(); | ||
compile() { | ||
if (!this.serverless.service.stepFunctions) { | ||
if (!this.serverless.service.stepFunctions.stateMachines) { | ||
const errorMessage = [ | ||
@@ -63,5 +67,6 @@ 'stepFunctions statement does not exists in serverless.yml', | ||
if (typeof this.serverless.service.stepFunctions[this.options.state] === 'undefined') { | ||
if (typeof this.serverless.service.stepFunctions.stateMachines[this.options.name] | ||
=== 'undefined') { | ||
const errorMessage = [ | ||
`Step function "${this.options.state}" is not exists`, | ||
`Step function "${this.options.name}" is not exists`, | ||
].join(''); | ||
@@ -71,10 +76,20 @@ throw new this.serverless.classes.Error(errorMessage); | ||
this.serverless.service.stepFunctions[this.options.state] = | ||
JSON.stringify(this.serverless.service.stepFunctions[this.options.state]); | ||
_.forEach(this.functionArns, (value, key) => { | ||
const regExp = new RegExp(`"Resource":"${key}"`, 'g'); | ||
this.serverless.service.stepFunctions[this.options.state] = | ||
this.serverless.service.stepFunctions[this.options.state] | ||
.replace(regExp, `"Resource":"${value}"`); | ||
this.serverless.service.stepFunctions.stateMachines[this.options.name] = | ||
JSON.stringify(this.serverless.service.stepFunctions.stateMachines[this.options.name]); | ||
_.forEach(this.functionArns, (functionArn, functionName) => { | ||
const regExp = new RegExp(`"Resource":"${functionName}"`, 'g'); | ||
this.serverless.service.stepFunctions.stateMachines[this.options.name] = | ||
this.serverless.service.stepFunctions.stateMachines[this.options.name] | ||
.replace(regExp, `"Resource":"${functionArn}"`); | ||
}); | ||
_.forEach(this.activityArns, (activityArn, activityName) => { | ||
const regExp = new RegExp(`"Resource":"${activityName}"`, 'g'); | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, | ||
(stepFunctionObj, stepFunctionKey) => { | ||
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] = | ||
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] | ||
.replace(regExp, `"Resource":"${activityArn}"`); | ||
}); | ||
}); | ||
return BbPromise.resolve(); | ||
@@ -84,3 +99,3 @@ }, | ||
compileAll() { | ||
if (!this.serverless.service.stepFunctions) { | ||
if (!this.serverless.service.stepFunctions.stateMachines) { | ||
const errorMessage = [ | ||
@@ -92,13 +107,26 @@ 'stepFunctions statement does not exists in serverless.yml', | ||
_.forEach(this.serverless.service.stepFunctions, (stepFunctionObj, stepFunctionKey) => { | ||
this.serverless.service.stepFunctions[stepFunctionKey] = JSON.stringify(stepFunctionObj); | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, | ||
(stepFunctionObj, stepFunctionKey) => { | ||
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] | ||
= JSON.stringify(stepFunctionObj); | ||
}); | ||
_.forEach(this.functionArns, (functionArn, functionName) => { | ||
const regExp = new RegExp(`"Resource":"${functionName}"`, 'g'); | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, | ||
(stepFunctionObj, stepFunctionKey) => { | ||
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] = | ||
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] | ||
.replace(regExp, `"Resource":"${functionArn}"`); | ||
}); | ||
}); | ||
_.forEach(this.functionArns, (functionObj, functionKey) => { | ||
const regExp = new RegExp(`"Resource":"${functionKey}"`, 'g'); | ||
_.forEach(this.serverless.service.stepFunctions, (stepFunctionObj, stepFunctionKey) => { | ||
this.serverless.service.stepFunctions[stepFunctionKey] = | ||
this.serverless.service.stepFunctions[stepFunctionKey] | ||
.replace(regExp, `"Resource":"${functionObj}"`); | ||
}); | ||
_.forEach(this.activityArns, (activityArn, activityName) => { | ||
const regExp = new RegExp(`"Resource":"${activityName}"`, 'g'); | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, | ||
(stepFunctionObj, stepFunctionKey) => { | ||
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] = | ||
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] | ||
.replace(regExp, `"Resource":"${activityArn}"`); | ||
}); | ||
}); | ||
@@ -105,0 +133,0 @@ return BbPromise.resolve(); |
@@ -18,2 +18,3 @@ 'use strict'; | ||
serverless.service.service = 'step-functions'; | ||
serverless.service.stepFunctions = {}; | ||
serverless.service.functions = { | ||
@@ -33,3 +34,3 @@ first: { | ||
}, | ||
state: 'hellofunc', | ||
name: 'hellofunc', | ||
data: 'inputData', | ||
@@ -47,3 +48,8 @@ }; | ||
yamlParserStub = sinon.stub(serverlessStepFunctions.serverless.yamlParser, 'parse') | ||
.returns(BbPromise.resolve({ stepFunctions: { stateMachines: 'stepFunctions' } })); | ||
.returns(BbPromise.resolve({ | ||
stepFunctions: { | ||
stateMachines: 'stepFunctions', | ||
activities: 'my-activity', | ||
}, | ||
})); | ||
serverlessStepFunctions.serverless.config.servicePath = 'servicePath'; | ||
@@ -56,3 +62,4 @@ }); | ||
expect(yamlParserStub.calledOnce).to.be.equal(true); | ||
expect(serverless.service.stepFunctions).to.be.equal('stepFunctions'); | ||
expect(serverless.service.stepFunctions.stateMachines).to.be.equal('stepFunctions'); | ||
expect(serverless.service.stepFunctions.activities).to.be.equal('my-activity'); | ||
serverlessStepFunctions.serverless.yamlParser.parse.restore(); | ||
@@ -74,7 +81,13 @@ }) | ||
yamlParserStub = sinon.stub(serverlessStepFunctions.serverless.yamlParser, 'parse') | ||
.returns(BbPromise.resolve({ stepFunctions: { stateMachines: '${self:defaults.region}' } })); | ||
.returns(BbPromise.resolve({ | ||
stepFunctions: { | ||
stateMachines: '${self:defaults.region}', | ||
activities: '${self:defaults.region}', | ||
}, | ||
})); | ||
serverlessStepFunctions.yamlParse() | ||
.then(() => { | ||
expect(yamlParserStub.calledOnce).to.be.equal(true); | ||
expect(serverless.service.stepFunctions).to.be.equal('us-east-1'); | ||
expect(serverless.service.stepFunctions.stateMachines).to.be.equal('us-east-1'); | ||
expect(serverless.service.stepFunctions.activities).to.be.equal('us-east-1'); | ||
}); | ||
@@ -90,3 +103,4 @@ }); | ||
it('should throw error when stateMachine name does not exists', () => { | ||
serverlessStepFunctions.stepFunctions = {}; | ||
serverlessStepFunctions.serverless.service.stepFunctions.stateMachines = {}; | ||
serverlessStepFunctions.options.name = 'someName'; | ||
expect(() => serverlessStepFunctions.compile()).to.throw(Error); | ||
@@ -96,3 +110,3 @@ }); | ||
it('should comple with correct params', () => { | ||
serverless.service.stepFunctions = { | ||
serverless.service.stepFunctions.stateMachines = { | ||
hellofunc: { | ||
@@ -108,3 +122,3 @@ States: { | ||
serverlessStepFunctions.compile().then(() => { | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.hellofunc) | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc) | ||
.to.be.equal('{"States":{"HelloWorld":{"Resource":"lambdaArn"}}}'); | ||
@@ -115,3 +129,3 @@ }); | ||
it('should comple with correct params when nested Resource', () => { | ||
serverlessStepFunctions.serverless.service.stepFunctions = { | ||
serverlessStepFunctions.serverless.service.stepFunctions.stateMachines = { | ||
hellofunc: { | ||
@@ -136,5 +150,49 @@ States: { | ||
serverlessStepFunctions.compile().then(() => { | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.hellofunc).to.be.equal(a); | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc) | ||
.to.be.equal(a); | ||
}); | ||
}); | ||
it('should comple with replacing activityArn', () => { | ||
serverless.service.stepFunctions.stateMachines = { | ||
hellofunc: { | ||
States: { | ||
HelloWorld: { | ||
Resource: 'someActivity', | ||
}, | ||
}, | ||
}, | ||
}; | ||
serverlessStepFunctions.activityArns.someActivity = 'activityArn'; | ||
serverlessStepFunctions.compile().then(() => { | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc) | ||
.to.be.equal('{"States":{"HelloWorld":{"Resource":"activityArn"}}}'); | ||
}); | ||
}); | ||
it('should comple with correct params when nested Resource with replacing activityArn', () => { | ||
serverlessStepFunctions.serverless.service.stepFunctions.stateMachines = { | ||
hellofunc: { | ||
States: { | ||
HelloWorld: { | ||
Resource: 'someActivity', | ||
HelloWorld: { | ||
Resource: 'someActivity', | ||
HelloWorld: { | ||
Resource: 'someActivity', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
let a = '{"States":{"HelloWorld":{"Resource":"activityArn","HelloWorld"'; | ||
a += ':{"Resource":"activityArn","HelloWorld":{"Resource":"activityArn"}}}}}'; | ||
serverlessStepFunctions.activityArns.someActivity = 'activityArn'; | ||
serverlessStepFunctions.compile().then(() => { | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc) | ||
.to.be.equal(a); | ||
}); | ||
}); | ||
}); | ||
@@ -216,3 +274,3 @@ | ||
it('should comple with correct params when nested Resource', () => { | ||
serverlessStepFunctions.serverless.service.stepFunctions = { | ||
serverlessStepFunctions.serverless.service.stepFunctions.stateMachines = { | ||
hellofunc: { | ||
@@ -237,6 +295,33 @@ States: { | ||
serverlessStepFunctions.compileAll().then(() => { | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.hellofunc).to.be.equal(a); | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc) | ||
.to.be.equal(a); | ||
}); | ||
}); | ||
it('should comple with correct params when nested Resource with replacing activityArn', () => { | ||
serverlessStepFunctions.serverless.service.stepFunctions.stateMachines = { | ||
hellofunc: { | ||
States: { | ||
HelloWorld: { | ||
Resource: 'someActivity', | ||
HelloWorld: { | ||
Resource: 'someActivity', | ||
HelloWorld: { | ||
Resource: 'someActivity', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
let a = '{"States":{"HelloWorld":{"Resource":"activityArn","HelloWorld"'; | ||
a += ':{"Resource":"activityArn","HelloWorld":{"Resource":"activityArn"}}}}}'; | ||
serverlessStepFunctions.activityArns.someActivity = 'activityArn'; | ||
serverlessStepFunctions.compileAll().then(() => { | ||
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc) | ||
.to.be.equal(a); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -46,3 +46,3 @@ 'use strict'; | ||
getIamRole(state) { | ||
const stateMachine = state || this.options.state; | ||
const stateMachine = state || this.options.name; | ||
return this.provider.request('IAM', | ||
@@ -68,3 +68,3 @@ 'getRole', | ||
const promises = []; | ||
_.forEach(this.serverless.service.stepFunctions, (value, key) => { | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, (value, key) => { | ||
promises.push(key); | ||
@@ -78,3 +78,3 @@ }); | ||
createIamRole(state) { | ||
const stateMachine = state || this.options.state; | ||
const stateMachine = state || this.options.name; | ||
return this.provider.request('IAM', | ||
@@ -112,3 +112,3 @@ 'createRole', | ||
deleteIamRole(state) { | ||
const stateMachine = state || this.options.state; | ||
const stateMachine = state || this.options.name; | ||
let policyArn; | ||
@@ -159,3 +159,3 @@ return this.provider.request('STS', | ||
const promises = []; | ||
_.forEach(this.serverless.service.stepFunctions, (value, key) => { | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, (value, key) => { | ||
promises.push(key); | ||
@@ -162,0 +162,0 @@ }); |
@@ -18,2 +18,3 @@ 'use strict'; | ||
serverless.service.service = 'step-functions'; | ||
serverless.service.stepFunctions = {}; | ||
serverless.service.functions = { | ||
@@ -33,3 +34,3 @@ first: { | ||
}, | ||
state: 'hellofunc', | ||
name: 'hellofunc', | ||
data: 'inputData', | ||
@@ -183,3 +184,3 @@ }; | ||
beforeEach(() => { | ||
serverless.service.stepFunctions = { | ||
serverless.service.stepFunctions.stateMachines = { | ||
helloHello: 'value', | ||
@@ -205,3 +206,3 @@ hogeHoge: 'value', | ||
beforeEach(() => { | ||
serverless.service.stepFunctions = { | ||
serverless.service.stepFunctions.stateMachines = { | ||
helloHello: 'value', | ||
@@ -208,0 +209,0 @@ hogeHoge: 'value', |
314
lib/index.js
'use strict'; | ||
const stateMachine = require('./stateMachine'); | ||
const activity = require('./activity'); | ||
const iam = require('./iam'); | ||
@@ -22,2 +23,3 @@ const dataProcessing = require('./dataProcessing'); | ||
stateMachine, | ||
activity, | ||
iam, | ||
@@ -38,6 +40,2 @@ dataProcessing, | ||
options: { | ||
state: { | ||
usage: 'Name of the State Machine', | ||
shortcut: 't', | ||
}, | ||
stage: { | ||
@@ -52,22 +50,43 @@ usage: 'Stage of the service', | ||
}, | ||
}, | ||
tasks: { | ||
usage: 'Deploy the Tasks of Step functions', | ||
lifecycleEvents: [ | ||
'deploy', | ||
], | ||
options: { | ||
state: { | ||
usage: 'Name of the Tasks', | ||
shortcut: 't', | ||
required: true, | ||
commands: { | ||
activities: { | ||
usage: 'Deploy the activities of Step functions', | ||
lifecycleEvents: [ | ||
'deploy', | ||
], | ||
options: { | ||
name: { | ||
usage: 'Name of the Task', | ||
shortcut: 'n', | ||
}, | ||
stage: { | ||
usage: 'Stage of the service', | ||
shortcut: 's', | ||
}, | ||
region: { | ||
usage: 'Region of the service', | ||
shortcut: 'r', | ||
}, | ||
}, | ||
}, | ||
stage: { | ||
usage: 'Stage of the service', | ||
shortcut: 's', | ||
statemachines: { | ||
usage: 'Deploy the StateMachines of Step functions', | ||
lifecycleEvents: [ | ||
'deploy', | ||
], | ||
options: { | ||
name: { | ||
usage: 'Name of StateMachine', | ||
shortcut: 'n', | ||
}, | ||
stage: { | ||
usage: 'Stage of the service', | ||
shortcut: 's', | ||
}, | ||
region: { | ||
usage: 'Region of the service', | ||
shortcut: 'r', | ||
}, | ||
}, | ||
}, | ||
region: { | ||
usage: 'Region of the service', | ||
shortcut: 'r', | ||
}, | ||
}, | ||
@@ -85,6 +104,2 @@ }, | ||
options: { | ||
state: { | ||
usage: 'Name of the State Machine', | ||
shortcut: 't', | ||
}, | ||
stage: { | ||
@@ -99,22 +114,43 @@ usage: 'Stage of the service', | ||
}, | ||
}, | ||
tasks: { | ||
usage: 'Remove the Tasks of Step functions', | ||
lifecycleEvents: [ | ||
'deploy', | ||
], | ||
options: { | ||
state: { | ||
usage: 'Name of the Tasks', | ||
shortcut: 't', | ||
required: true, | ||
commands: { | ||
activities: { | ||
usage: 'Remove the activities of Step functions', | ||
lifecycleEvents: [ | ||
'remove', | ||
], | ||
options: { | ||
name: { | ||
usage: 'Name of the Task', | ||
shortcut: 'n', | ||
}, | ||
stage: { | ||
usage: 'Stage of the service', | ||
shortcut: 's', | ||
}, | ||
region: { | ||
usage: 'Region of the service', | ||
shortcut: 'r', | ||
}, | ||
}, | ||
}, | ||
stage: { | ||
usage: 'Stage of the service', | ||
shortcut: 's', | ||
statemachines: { | ||
usage: 'Remove the StateMachines of Step functions', | ||
lifecycleEvents: [ | ||
'remove', | ||
], | ||
options: { | ||
name: { | ||
usage: 'Name of StateMachine', | ||
shortcut: 'n', | ||
}, | ||
stage: { | ||
usage: 'Stage of the service', | ||
shortcut: 's', | ||
}, | ||
region: { | ||
usage: 'Region of the service', | ||
shortcut: 'r', | ||
}, | ||
}, | ||
}, | ||
region: { | ||
usage: 'Region of the service', | ||
shortcut: 'r', | ||
}, | ||
}, | ||
@@ -132,5 +168,5 @@ }, | ||
options: { | ||
state: { | ||
name: { | ||
usage: 'Name of the State Machine', | ||
shortcut: 't', | ||
shortcut: 'n', | ||
required: true, | ||
@@ -163,17 +199,162 @@ }, | ||
'deploy:stepf:deploy': () => BbPromise.bind(this) | ||
.then(this.allDeploy), | ||
'remove:stepf:remove': () => BbPromise.bind(this) | ||
.then(this.allRemove), | ||
'deploy:stepf:statemachines:deploy': () => BbPromise.bind(this) | ||
.then(this.stateMachineDeploy), | ||
'remove:stepf:remove': () => BbPromise.bind(this) | ||
'remove:stepf:statemachines:remove': () => BbPromise.bind(this) | ||
.then(this.stateMachineRemove), | ||
'invoke:stepf:invoke': () => BbPromise.bind(this) | ||
.then(this.stateMachineInvoke), | ||
// 'deploy:tasks:deploy': () => BbPromise.bind(this) | ||
// .then(this.tasksDeploy), | ||
// 'remove:tasks:remove': () => BbPromise.bind(this) | ||
// .then(this.tasksRemove), | ||
'deploy:stepf:activities:deploy': () => BbPromise.bind(this) | ||
.then(this.activityDeploy), | ||
'remove:stepf:activities:remove': () => BbPromise.bind(this) | ||
.then(this.activityRemove), | ||
}; | ||
} | ||
allDeploy() { | ||
this.serverless.cli.log('Start to deploy for all stateMachies and activities...'); | ||
return BbPromise.bind(this) | ||
.then(this.yamlParse) | ||
.then(this.checkActivitySettings) | ||
.then(this.getActivityArns) | ||
.then(this.describeActivities) | ||
.then(this.createActivities) | ||
.then(this.getStateMachineNames) | ||
.then(this.getFunctionArns) | ||
.then(this.compileAll) | ||
.then(this.getIamRoles) | ||
.then(this.deleteStateMachines) | ||
.then(this.createStateMachines) | ||
.then(() => { | ||
this.serverless.cli.consoleLog(''); | ||
this.serverless.cli.log('Deployed all stateMachies and activities\n'); | ||
let message = ''; | ||
message += `${chalk.yellow.underline('Service Information')}\n`; | ||
message += `${chalk.yellow('service:')} ${this.service}\n`; | ||
message += `${chalk.yellow('stage:')} ${this.stage}\n`; | ||
message += `${chalk.yellow('region:')} ${this.region}\n\n`; | ||
message += `${chalk.yellow.underline('State Machine Information')}\n`; | ||
_.forEach(this.stateMachineArns, (arn, name) => { | ||
message += `${chalk.yellow(name)}${chalk.yellow(':')} ${arn}\n`; | ||
}); | ||
message += '\n'; | ||
message += `${chalk.yellow.underline('Deployed Activity ARNs')}\n`; | ||
_.forEach(this.activityArns, (value, key) => { | ||
message += `${chalk.yellow(key)}${chalk.yellow(':')} `; | ||
message += `${value}\n`; | ||
}); | ||
this.serverless.cli.consoleLog(message); | ||
return BbPromise.resolve(); | ||
}); | ||
} | ||
allRemove() { | ||
this.serverless.cli.log('Start to remove for all statemachies and activities...'); | ||
return BbPromise.bind(this) | ||
.then(this.yamlParse) | ||
.then(this.deleteIamRoles) | ||
.then(this.getStateMachineNames) | ||
.then(this.deleteStateMachines) | ||
.then(this.checkActivitySettings) | ||
.then(this.getActivityArns) | ||
.then(this.describeActivities) | ||
.then(this.deleteActivities) | ||
.then(() => { | ||
this.serverless.cli.log('Removed for all statemachies and activities...'); | ||
}); | ||
} | ||
activityDeploy() { | ||
if (this.options.name) { | ||
this.serverless.cli.log(`Start to deploy ${this.options.name} activity...`); | ||
return BbPromise.bind(this) | ||
.then(this.yamlParse) | ||
.then(this.checkActivitySetting) | ||
.then(this.getActivityArn) | ||
.then(this.describeActivity) | ||
.then(() => { | ||
if (this.deployedActivities[this.options.name] === 'notDeployed') { | ||
return BbPromise.bind(this) | ||
.then(this.createActivity) | ||
.then(() => { | ||
this.serverless.cli.log('Finished to deploy'); | ||
let message = ''; | ||
message += `${chalk.yellow.underline('Service Information')}\n`; | ||
message += `${chalk.yellow('service:')} ${this.service}\n`; | ||
message += `${chalk.yellow('stage:')} ${this.stage}\n`; | ||
message += `${chalk.yellow('region:')} ${this.region}\n\n`; | ||
message += `${chalk.yellow.underline('Deployed Activity ARN')}\n`; | ||
message += `${chalk.yellow(this.options.name)}${chalk.yellow(':')} `; | ||
message += `${this.activityArns[this.options.name]}\n`; | ||
this.serverless.cli.consoleLog(message); | ||
return BbPromise.resolve(); | ||
}); | ||
} | ||
this.serverless.cli.log(`${this.options.name} activity have already deployed`); | ||
return BbPromise.resolve(); | ||
}); | ||
} | ||
this.serverless.cli.log('Start to deploy all activities...'); | ||
return BbPromise.bind(this) | ||
.then(this.yamlParse) | ||
.then(this.checkActivitySettings) | ||
.then(this.getActivityArns) | ||
.then(this.describeActivities) | ||
.then(this.createActivities) | ||
.then(() => { | ||
this.serverless.cli.log('Finish to deploy'); | ||
let message = ''; | ||
message += `${chalk.yellow.underline('Service Information')}\n`; | ||
message += `${chalk.yellow('service:')} ${this.service}\n`; | ||
message += `${chalk.yellow('stage:')} ${this.stage}\n`; | ||
message += `${chalk.yellow('region:')} ${this.region}\n\n`; | ||
message += `${chalk.yellow.underline('Deployed Activity ARNs')}\n`; | ||
_.forEach(this.activityArns, (value, key) => { | ||
message += `${chalk.yellow(key)}${chalk.yellow(':')} `; | ||
message += `${value}\n`; | ||
}); | ||
this.serverless.cli.consoleLog(message); | ||
return BbPromise.resolve(); | ||
}); | ||
} | ||
activityRemove() { | ||
if (this.options.name) { | ||
this.serverless.cli.log(`Start to remove ${this.options.name} activity...`); | ||
return BbPromise.bind(this) | ||
.then(this.yamlParse) | ||
.then(this.checkActivitySetting) | ||
.then(this.getActivityArn) | ||
.then(this.describeActivity) | ||
.then(() => { | ||
if (this.deployedActivities[this.options.name] === 'deployed') { | ||
return BbPromise.bind(this) | ||
.then(this.deleteActivity) | ||
.then(() => { | ||
this.serverless.cli.log('Finished to remove'); | ||
}); | ||
} | ||
this.serverless.cli.log(`${this.options.name} activity is not deployed`); | ||
return BbPromise.resolve(); | ||
}); | ||
} | ||
this.serverless.cli.log('Start to remove all activities...'); | ||
return BbPromise.bind(this) | ||
.then(this.yamlParse) | ||
.then(this.checkActivitySettings) | ||
.then(this.getActivityArns) | ||
.then(this.describeActivities) | ||
.then(this.deleteActivities) | ||
.then(() => { | ||
this.serverless.cli.log('Removed all activities'); | ||
return BbPromise.resolve(); | ||
}); | ||
} | ||
stateMachineDeploy() { | ||
if (this.options.state) { | ||
this.serverless.cli.log(`Start to deploy ${this.options.state} step function...`); | ||
if (this.options.name) { | ||
this.serverless.cli.log(`Start to deploy ${this.options.name} step function...`); | ||
return BbPromise.bind(this) | ||
@@ -183,2 +364,3 @@ .then(this.yamlParse) | ||
.then(this.getFunctionArns) | ||
.then(this.getActivityArns) | ||
.then(this.compile) | ||
@@ -190,3 +372,3 @@ .then(this.getIamRole) | ||
this.serverless.cli.consoleLog(''); | ||
this.serverless.cli.log(`Finish to deploy ${this.options.state} step function`); | ||
this.serverless.cli.log(`Finish to deploy ${this.options.name} step function`); | ||
let message = ''; | ||
@@ -198,4 +380,4 @@ message += `${chalk.yellow.underline('Service Information')}\n`; | ||
message += `${chalk.yellow.underline('State Machine Information')}\n`; | ||
message += `${chalk.yellow(this.options.state)}${chalk.yellow(':')} `; | ||
message += `${this.stateMachineArns[this.options.state]}\n`; | ||
message += `${chalk.yellow(this.options.name)}${chalk.yellow(':')} `; | ||
message += `${this.stateMachineArns[this.options.name]}\n`; | ||
this.serverless.cli.consoleLog(message); | ||
@@ -205,3 +387,3 @@ return BbPromise.resolve(); | ||
} | ||
this.serverless.cli.log('Start to deploy all step functions...'); | ||
this.serverless.cli.log('Start to deploy all stateMachines of Step Functions...'); | ||
return BbPromise.bind(this) | ||
@@ -217,3 +399,3 @@ .then(this.yamlParse) | ||
this.serverless.cli.consoleLog(''); | ||
this.serverless.cli.log('Finish to deploy all step functions'); | ||
this.serverless.cli.log('Finished to deploy all stateMachines'); | ||
let message = ''; | ||
@@ -234,3 +416,3 @@ message += `${chalk.yellow.underline('Service Information')}\n`; | ||
stateMachineRemove() { | ||
if (this.options.state) { | ||
if (this.options.name) { | ||
return BbPromise.bind(this) | ||
@@ -242,3 +424,3 @@ .then(this.yamlParse) | ||
.then(() => { | ||
this.serverless.cli.log(`Remove ${this.options.state}`); | ||
this.serverless.cli.log(`Remove ${this.options.name}`); | ||
return BbPromise.resolve(); | ||
@@ -253,13 +435,3 @@ }); | ||
.then(() => { | ||
this.serverless.cli.log('Remove all state machine'); | ||
let message = ''; | ||
message += `${chalk.yellow.underline('Service Information')}\n`; | ||
message += `${chalk.yellow('service:')} ${this.service}\n`; | ||
message += `${chalk.yellow('stage:')} ${this.stage}\n`; | ||
message += `${chalk.yellow('region:')} ${this.region}\n\n`; | ||
message += `${chalk.yellow.underline('Deleted State Machine')}\n`; | ||
_.forEach(this.stateMachineArns, (arn, name) => { | ||
message += `${chalk.yellow(name)}${chalk.yellow(':')} ${arn}\n`; | ||
}); | ||
this.serverless.cli.consoleLog(message); | ||
this.serverless.cli.log('Removed all stateMachines'); | ||
return BbPromise.resolve(); | ||
@@ -266,0 +438,0 @@ }); |
@@ -33,3 +33,3 @@ 'use strict'; | ||
}, | ||
state: 'hellofunc', | ||
name: 'hellofunc', | ||
data: 'inputData', | ||
@@ -78,7 +78,7 @@ }; | ||
const deployStub = sinon | ||
.stub(serverlessStepFunctions, 'stateMachineDeploy').returns(BbPromise.resolve()); | ||
.stub(serverlessStepFunctions, 'allDeploy').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.hooks['deploy:stepf:deploy']() | ||
.then(() => { | ||
expect(deployStub.calledOnce).to.be.equal(true); | ||
serverlessStepFunctions.stateMachineDeploy.restore(); | ||
serverlessStepFunctions.allDeploy.restore(); | ||
}); | ||
@@ -89,6 +89,26 @@ }); | ||
const removeStub = sinon | ||
.stub(serverlessStepFunctions, 'stateMachineRemove').returns(BbPromise.resolve()); | ||
.stub(serverlessStepFunctions, 'allRemove').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.hooks['remove:stepf:remove']() | ||
.then(() => { | ||
expect(removeStub.calledOnce).to.be.equal(true); | ||
serverlessStepFunctions.allRemove.restore(); | ||
}); | ||
}); | ||
it('should run deploy:stepf:statemachines:deploy promise chain in order', () => { | ||
const deployStub = sinon | ||
.stub(serverlessStepFunctions, 'stateMachineDeploy').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.hooks['deploy:stepf:statemachines:deploy']() | ||
.then(() => { | ||
expect(deployStub.calledOnce).to.be.equal(true); | ||
serverlessStepFunctions.stateMachineDeploy.restore(); | ||
}); | ||
}); | ||
it('should run remove:stepf:statemachines:remove promise chain in order', () => { | ||
const removeStub = sinon | ||
.stub(serverlessStepFunctions, 'stateMachineRemove').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.hooks['remove:stepf:statemachines:remove']() | ||
.then(() => { | ||
expect(removeStub.calledOnce).to.be.equal(true); | ||
serverlessStepFunctions.stateMachineRemove.restore(); | ||
@@ -108,2 +128,22 @@ }); | ||
it('should run deploy:stepf:activities:deploy promise chain in order', () => { | ||
const deployActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'activityDeploy').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.hooks['deploy:stepf:activities:deploy']() | ||
.then(() => { | ||
expect(deployActivityStub.calledOnce).to.be.equal(true); | ||
serverlessStepFunctions.activityDeploy.restore(); | ||
}); | ||
}); | ||
it('should run remove:stepf:activities:remove promise chain in order', () => { | ||
const removeActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'activityRemove').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.hooks['remove:stepf:activities:remove']() | ||
.then(() => { | ||
expect(removeActivityStub.calledOnce).to.be.equal(true); | ||
serverlessStepFunctions.activityRemove.restore(); | ||
}); | ||
}); | ||
it('should set an empty options object if no options are given', () => { | ||
@@ -115,4 +155,100 @@ const serverlessStepFunctionsWithEmptyOptions = new ServerlessStepFunctions(serverless); | ||
describe('#allDeploy()', () => { | ||
it('should run promise chain in order', () => { | ||
const yamlParseStub = sinon | ||
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
const checkActivitySettingsStub = sinon | ||
.stub(serverlessStepFunctions, 'checkActivitySettings').returns(BbPromise.resolve()); | ||
const getActivityArnsStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArns').returns(BbPromise.resolve()); | ||
const describeActivitiesStub = sinon | ||
.stub(serverlessStepFunctions, 'describeActivities').returns(BbPromise.resolve()); | ||
const createActivitiesStub = sinon | ||
.stub(serverlessStepFunctions, 'createActivities').returns(BbPromise.resolve()); | ||
const getStateMachineNamesStub = sinon | ||
.stub(serverlessStepFunctions, 'getStateMachineNames').returns(BbPromise.resolve()); | ||
const getFunctionArnsStub = sinon | ||
.stub(serverlessStepFunctions, 'getFunctionArns').returns(BbPromise.resolve()); | ||
const compileAllStub = sinon | ||
.stub(serverlessStepFunctions, 'compileAll').returns(BbPromise.resolve()); | ||
const getIamRolesStub = sinon | ||
.stub(serverlessStepFunctions, 'getIamRoles').returns(BbPromise.resolve()); | ||
const deleteStateMachinesStub = sinon | ||
.stub(serverlessStepFunctions, 'deleteStateMachines').returns(BbPromise.resolve()); | ||
const createStateMachinesStub = sinon | ||
.stub(serverlessStepFunctions, 'createStateMachines').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.allDeploy() | ||
.then(() => { | ||
expect(yamlParseStub.calledOnce).to.be.equal(true); | ||
expect(checkActivitySettingsStub.calledAfter(yamlParseStub)).to.be.equal(true); | ||
expect(getActivityArnsStub.calledAfter(checkActivitySettingsStub)).to.be.equal(true); | ||
expect(describeActivitiesStub.calledAfter(getActivityArnsStub)).to.be.equal(true); | ||
expect(createActivitiesStub.calledAfter(describeActivitiesStub)).to.be.equal(true); | ||
expect(getStateMachineNamesStub.calledAfter(createActivitiesStub)).to.be.equal(true); | ||
expect(getFunctionArnsStub.calledAfter(getStateMachineNamesStub)).to.be.equal(true); | ||
expect(compileAllStub.calledAfter(getFunctionArnsStub)).to.be.equal(true); | ||
expect(getIamRolesStub.calledAfter(compileAllStub)).to.be.equal(true); | ||
expect(deleteStateMachinesStub.calledAfter(getIamRolesStub)).to.be.equal(true); | ||
expect(createStateMachinesStub.calledAfter(deleteStateMachinesStub)).to.be.equal(true); | ||
serverlessStepFunctions.yamlParse.restore(); | ||
serverlessStepFunctions.checkActivitySettings.restore(); | ||
serverlessStepFunctions.getActivityArns.restore(); | ||
serverlessStepFunctions.describeActivities.restore(); | ||
serverlessStepFunctions.createActivities.restore(); | ||
serverlessStepFunctions.getStateMachineNames.restore(); | ||
serverlessStepFunctions.getFunctionArns.restore(); | ||
serverlessStepFunctions.compileAll.restore(); | ||
serverlessStepFunctions.getIamRoles.restore(); | ||
serverlessStepFunctions.deleteStateMachines.restore(); | ||
serverlessStepFunctions.createStateMachines.restore(); | ||
}); | ||
}); | ||
}); | ||
describe('#allRemove()', () => { | ||
it('should run promise chain in order', () => { | ||
const yamlParseStub = sinon | ||
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
const deleteIamRolesStub = sinon | ||
.stub(serverlessStepFunctions, 'deleteIamRoles').returns(BbPromise.resolve()); | ||
const getStateMachineNamesStub = sinon | ||
.stub(serverlessStepFunctions, 'getStateMachineNames').returns(BbPromise.resolve()); | ||
const deleteStateMachinesStub = sinon | ||
.stub(serverlessStepFunctions, 'deleteStateMachines').returns(BbPromise.resolve()); | ||
const checkActivitySettingsStub = sinon | ||
.stub(serverlessStepFunctions, 'checkActivitySettings').returns(BbPromise.resolve()); | ||
const getActivityArnsStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArns').returns(BbPromise.resolve()); | ||
const describeActivitiesStub = sinon | ||
.stub(serverlessStepFunctions, 'describeActivities').returns(BbPromise.resolve()); | ||
const deleteActivitiesStub = sinon | ||
.stub(serverlessStepFunctions, 'deleteActivities').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.allRemove() | ||
.then(() => { | ||
expect(yamlParseStub.calledOnce).to.be.equal(true); | ||
expect(deleteIamRolesStub.calledAfter(yamlParseStub)).to.be.equal(true); | ||
expect(getStateMachineNamesStub.calledAfter(deleteIamRolesStub)).to.be.equal(true); | ||
expect(deleteStateMachinesStub.calledAfter(getStateMachineNamesStub)).to.be.equal(true); | ||
expect(checkActivitySettingsStub.calledAfter(deleteStateMachinesStub)).to.be.equal(true); | ||
expect(getActivityArnsStub.calledAfter(checkActivitySettingsStub)).to.be.equal(true); | ||
expect(describeActivitiesStub.calledAfter(getActivityArnsStub)).to.be.equal(true); | ||
expect(deleteActivitiesStub.calledAfter(describeActivitiesStub)).to.be.equal(true); | ||
serverlessStepFunctions.yamlParse.restore(); | ||
serverlessStepFunctions.deleteIamRoles.restore(); | ||
serverlessStepFunctions.getStateMachineNames.restore(); | ||
serverlessStepFunctions.deleteStateMachines.restore(); | ||
serverlessStepFunctions.checkActivitySettings.restore(); | ||
serverlessStepFunctions.getActivityArns.restore(); | ||
serverlessStepFunctions.describeActivities.restore(); | ||
serverlessStepFunctions.deleteActivities.restore(); | ||
}); | ||
}); | ||
}); | ||
describe('#stateMachineDeploy()', () => { | ||
it('should run promise chain in order when state is given', () => { | ||
it('should run promise chain in order when name is given', () => { | ||
const yamlParseStub = sinon | ||
@@ -124,2 +260,4 @@ .stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
.stub(serverlessStepFunctions, 'getFunctionArns').returns(BbPromise.resolve()); | ||
const getActivityArnsStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArns').returns(BbPromise.resolve()); | ||
const compileStub = sinon | ||
@@ -139,3 +277,4 @@ .stub(serverlessStepFunctions, 'compile').returns(BbPromise.resolve()); | ||
expect(getFunctionArnsStub.calledAfter(getStateMachineArnStub)).to.be.equal(true); | ||
expect(compileStub.calledAfter(getFunctionArnsStub)).to.be.equal(true); | ||
expect(getActivityArnsStub.calledAfter(getFunctionArnsStub)).to.be.equal(true); | ||
expect(compileStub.calledAfter(getActivityArnsStub)).to.be.equal(true); | ||
expect(getIamRoleStub.calledAfter(compileStub)).to.be.equal(true); | ||
@@ -148,2 +287,3 @@ expect(deleteStateMachineStub.calledAfter(getIamRoleStub)).to.be.equal(true); | ||
serverlessStepFunctions.getFunctionArns.restore(); | ||
serverlessStepFunctions.getActivityArns.restore(); | ||
serverlessStepFunctions.compile.restore(); | ||
@@ -157,4 +297,4 @@ serverlessStepFunctions.getIamRole.restore(); | ||
it('should run promise chain in order when state is not given', () => { | ||
serverlessStepFunctions.options.state = null; | ||
it('should run promise chain in order when name is not given', () => { | ||
serverlessStepFunctions.options.name = null; | ||
const yamlParseStub = sinon | ||
@@ -196,3 +336,3 @@ .stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
describe('#stateMachineRemove()', () => { | ||
it('should run promise chain in order when state is given', () => { | ||
it('should run promise chain in order when name is given', () => { | ||
const yamlParseStub = sinon | ||
@@ -221,4 +361,4 @@ .stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
it('should run promise chain in order when state is not given', () => { | ||
serverlessStepFunctions.options.state = null; | ||
it('should run promise chain in order when name is not given', () => { | ||
serverlessStepFunctions.options.name = null; | ||
const yamlParseStub = sinon | ||
@@ -307,3 +447,181 @@ .stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
}); | ||
describe('#activityDeploy()', () => { | ||
it('should run promise chain in order when name is given with notDeployed', () => { | ||
serverlessStepFunctions.deployedActivities.hellofunc = 'notDeployed'; | ||
const yamlParseStub = sinon | ||
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
const checkActivitySettingStub = sinon | ||
.stub(serverlessStepFunctions, 'checkActivitySetting').returns(BbPromise.resolve()); | ||
const getActivityArnStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArn').returns(BbPromise.resolve()); | ||
const describeActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'describeActivity').returns(BbPromise.resolve()); | ||
const createActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'createActivity').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.activityDeploy() | ||
.then(() => { | ||
expect(yamlParseStub.calledOnce).to.be.equal(true); | ||
expect(checkActivitySettingStub.calledAfter(yamlParseStub)).to.be.equal(true); | ||
expect(getActivityArnStub.calledAfter(checkActivitySettingStub)).to.be.equal(true); | ||
expect(describeActivityStub.calledAfter(getActivityArnStub)).to.be.equal(true); | ||
expect(createActivityStub.calledAfter(describeActivityStub)).to.be.equal(true); | ||
serverlessStepFunctions.yamlParse.restore(); | ||
serverlessStepFunctions.checkActivitySetting.restore(); | ||
serverlessStepFunctions.getActivityArn.restore(); | ||
serverlessStepFunctions.describeActivity.restore(); | ||
serverlessStepFunctions.createActivity.restore(); | ||
}); | ||
}); | ||
it('should run promise chain in order when name is given with deployed', () => { | ||
serverlessStepFunctions.deployedActivities.hellofunc = 'deployed'; | ||
const yamlParseStub = sinon | ||
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
const checkActivitySettingStub = sinon | ||
.stub(serverlessStepFunctions, 'checkActivitySetting').returns(BbPromise.resolve()); | ||
const getActivityArnStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArn').returns(BbPromise.resolve()); | ||
const describeActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'describeActivity').returns(BbPromise.resolve()); | ||
const createActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'createActivity').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.activityDeploy() | ||
.then(() => { | ||
expect(yamlParseStub.calledOnce).to.be.equal(true); | ||
expect(checkActivitySettingStub.calledAfter(yamlParseStub)).to.be.equal(true); | ||
expect(getActivityArnStub.calledAfter(checkActivitySettingStub)).to.be.equal(true); | ||
expect(describeActivityStub.calledAfter(getActivityArnStub)).to.be.equal(true); | ||
expect(createActivityStub.calledAfter(describeActivityStub)).to.be.equal(false); | ||
serverlessStepFunctions.yamlParse.restore(); | ||
serverlessStepFunctions.checkActivitySetting.restore(); | ||
serverlessStepFunctions.getActivityArn.restore(); | ||
serverlessStepFunctions.describeActivity.restore(); | ||
serverlessStepFunctions.createActivity.restore(); | ||
}); | ||
}); | ||
it('should run promise chain in order when name is not given', () => { | ||
serverlessStepFunctions.options.name = null; | ||
const yamlParseStub = sinon | ||
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
const checkActivitySettingsStub = sinon | ||
.stub(serverlessStepFunctions, 'checkActivitySettings').returns(BbPromise.resolve()); | ||
const getActivityArnsStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArns').returns(BbPromise.resolve()); | ||
const describeActivitiesStub = sinon | ||
.stub(serverlessStepFunctions, 'describeActivities').returns(BbPromise.resolve()); | ||
const createActivitiesStub = sinon | ||
.stub(serverlessStepFunctions, 'createActivities').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.activityDeploy() | ||
.then(() => { | ||
expect(yamlParseStub.calledOnce).to.be.equal(true); | ||
expect(checkActivitySettingsStub.calledAfter(yamlParseStub)).to.be.equal(true); | ||
expect(getActivityArnsStub.calledAfter(checkActivitySettingsStub)).to.be.equal(true); | ||
expect(describeActivitiesStub.calledAfter(getActivityArnsStub)).to.be.equal(true); | ||
expect(createActivitiesStub.calledAfter(describeActivitiesStub)).to.be.equal(true); | ||
serverlessStepFunctions.yamlParse.restore(); | ||
serverlessStepFunctions.checkActivitySettings.restore(); | ||
serverlessStepFunctions.getActivityArns.restore(); | ||
serverlessStepFunctions.describeActivities.restore(); | ||
serverlessStepFunctions.createActivities.restore(); | ||
}); | ||
}); | ||
}); | ||
describe('#activityDeploy()', () => { | ||
it('should run promise chain in order when name is given with deployed', () => { | ||
serverlessStepFunctions.deployedActivities.hellofunc = 'deployed'; | ||
const yamlParseStub = sinon | ||
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
const checkActivitySettingStub = sinon | ||
.stub(serverlessStepFunctions, 'checkActivitySetting').returns(BbPromise.resolve()); | ||
const getActivityArnStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArn').returns(BbPromise.resolve()); | ||
const describeActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'describeActivity').returns(BbPromise.resolve()); | ||
const deleteActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'deleteActivity').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.activityRemove() | ||
.then(() => { | ||
expect(yamlParseStub.calledOnce).to.be.equal(true); | ||
expect(checkActivitySettingStub.calledAfter(yamlParseStub)).to.be.equal(true); | ||
expect(getActivityArnStub.calledAfter(checkActivitySettingStub)).to.be.equal(true); | ||
expect(describeActivityStub.calledAfter(getActivityArnStub)).to.be.equal(true); | ||
expect(deleteActivityStub.calledAfter(describeActivityStub)).to.be.equal(true); | ||
serverlessStepFunctions.yamlParse.restore(); | ||
serverlessStepFunctions.checkActivitySetting.restore(); | ||
serverlessStepFunctions.getActivityArn.restore(); | ||
serverlessStepFunctions.describeActivity.restore(); | ||
serverlessStepFunctions.deleteActivity.restore(); | ||
}); | ||
}); | ||
it('should run promise chain in order when name is given with notDeployed', () => { | ||
serverlessStepFunctions.deployedActivities.hellofunc = 'notDeployed'; | ||
const yamlParseStub = sinon | ||
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
const checkActivitySettingStub = sinon | ||
.stub(serverlessStepFunctions, 'checkActivitySetting').returns(BbPromise.resolve()); | ||
const getActivityArnStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArn').returns(BbPromise.resolve()); | ||
const describeActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'describeActivity').returns(BbPromise.resolve()); | ||
const deleteActivityStub = sinon | ||
.stub(serverlessStepFunctions, 'deleteActivity').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.activityRemove() | ||
.then(() => { | ||
expect(yamlParseStub.calledOnce).to.be.equal(true); | ||
expect(checkActivitySettingStub.calledAfter(yamlParseStub)).to.be.equal(true); | ||
expect(getActivityArnStub.calledAfter(checkActivitySettingStub)).to.be.equal(true); | ||
expect(describeActivityStub.calledAfter(getActivityArnStub)).to.be.equal(true); | ||
expect(deleteActivityStub.calledAfter(describeActivityStub)).to.be.equal(false); | ||
serverlessStepFunctions.yamlParse.restore(); | ||
serverlessStepFunctions.checkActivitySetting.restore(); | ||
serverlessStepFunctions.getActivityArn.restore(); | ||
serverlessStepFunctions.describeActivity.restore(); | ||
serverlessStepFunctions.deleteActivity.restore(); | ||
}); | ||
}); | ||
it('should run promise chain in order when name is not given', () => { | ||
serverlessStepFunctions.options.name = null; | ||
const yamlParseStub = sinon | ||
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve()); | ||
const checkActivitySettingsStub = sinon | ||
.stub(serverlessStepFunctions, 'checkActivitySettings').returns(BbPromise.resolve()); | ||
const getActivityArnsStub = sinon | ||
.stub(serverlessStepFunctions, 'getActivityArns').returns(BbPromise.resolve()); | ||
const describeActivitiesStub = sinon | ||
.stub(serverlessStepFunctions, 'describeActivities').returns(BbPromise.resolve()); | ||
const deleteActivitiesStub = sinon | ||
.stub(serverlessStepFunctions, 'deleteActivities').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.activityRemove() | ||
.then(() => { | ||
expect(yamlParseStub.calledOnce).to.be.equal(true); | ||
expect(checkActivitySettingsStub.calledAfter(yamlParseStub)).to.be.equal(true); | ||
expect(getActivityArnsStub.calledAfter(checkActivitySettingsStub)).to.be.equal(true); | ||
expect(describeActivitiesStub.calledAfter(getActivityArnsStub)).to.be.equal(true); | ||
expect(deleteActivitiesStub.calledAfter(describeActivitiesStub)).to.be.equal(true); | ||
serverlessStepFunctions.yamlParse.restore(); | ||
serverlessStepFunctions.checkActivitySettings.restore(); | ||
serverlessStepFunctions.getActivityArns.restore(); | ||
serverlessStepFunctions.describeActivities.restore(); | ||
serverlessStepFunctions.deleteActivities.restore(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -12,3 +12,3 @@ 'use strict'; | ||
getStateMachineArn(state) { | ||
const stateMachine = state || this.options.state; | ||
const stateMachine = state || this.options.name; | ||
return this.provider.request('STS', | ||
@@ -35,3 +35,3 @@ 'getCallerIdentity', | ||
.then((result) => { | ||
_.forEach(this.serverless.service.stepFunctions, (value, key) => { | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, (value, key) => { | ||
this.stateMachineArns[key] = | ||
@@ -47,3 +47,3 @@ `arn:aws:states:${this.region}:${result.Account}:`; | ||
deleteStateMachine(state) { | ||
const stateMachine = state || this.options.state; | ||
const stateMachine = state || this.options.name; | ||
return this.provider.request('StepFunctions', | ||
@@ -61,3 +61,3 @@ 'deleteStateMachine', | ||
const promises = []; | ||
_.forEach(this.serverless.service.stepFunctions, (value, key) => { | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, (value, key) => { | ||
promises.push(key); | ||
@@ -72,7 +72,7 @@ }); | ||
createStateMachine(state) { | ||
const stateMachine = state || this.options.state; | ||
const stateMachine = state || this.options.name; | ||
return this.provider.request('StepFunctions', | ||
'createStateMachine', | ||
{ | ||
definition: this.serverless.service.stepFunctions[stateMachine], | ||
definition: this.serverless.service.stepFunctions.stateMachines[stateMachine], | ||
name: this.getStateMachineName(stateMachine), | ||
@@ -97,3 +97,3 @@ roleArn: this.iamRoleArn[stateMachine], | ||
const promises = []; | ||
_.forEach(this.serverless.service.stepFunctions, (value, key) => { | ||
_.forEach(this.serverless.service.stepFunctions.stateMachines, (value, key) => { | ||
promises.push(key); | ||
@@ -111,3 +111,3 @@ }); | ||
{ | ||
stateMachineArn: this.stateMachineArns[this.options.state], | ||
stateMachineArn: this.stateMachineArns[this.options.name], | ||
input: this.options.data, | ||
@@ -114,0 +114,0 @@ }, |
@@ -18,2 +18,3 @@ 'use strict'; | ||
serverless.service.service = 'step-functions'; | ||
serverless.service.stepFunctions = {}; | ||
serverless.service.functions = { | ||
@@ -33,3 +34,3 @@ first: { | ||
}, | ||
state: 'hellofunc', | ||
name: 'hellofunc', | ||
data: 'inputData', | ||
@@ -115,3 +116,3 @@ }; | ||
.returns(BbPromise.resolve()); | ||
serverless.service.stepFunctions = { state: 'state' }; | ||
serverless.service.stepFunctions.stateMachines = { name: 'state' }; | ||
}); | ||
@@ -129,3 +130,3 @@ | ||
definition: serverlessStepFunctions | ||
.serverless.service.stepFunctions.hellofunc, | ||
.serverless.service.stepFunctions.stateMachines.hellofunc, | ||
name: `${serverless.service.service}-${stage}-hellofunc`, | ||
@@ -151,3 +152,3 @@ roleArn: serverlessStepFunctions.iamRoleArn.hellofunc, | ||
definition: serverlessStepFunctions | ||
.serverless.service.stepFunctions.state, | ||
.serverless.service.stepFunctions.stateMachines.state, | ||
name: `${serverless.service.service}-${stage}-state`, | ||
@@ -292,3 +293,3 @@ roleArn: serverlessStepFunctions.iamRoleArn.state, | ||
beforeEach(() => { | ||
serverless.service.stepFunctions = { | ||
serverless.service.stepFunctions.stateMachines = { | ||
helloHello: 'value', | ||
@@ -322,3 +323,3 @@ }; | ||
beforeEach(() => { | ||
serverless.service.stepFunctions = { | ||
serverless.service.stepFunctions.stateMachines = { | ||
helloHello: 'value', | ||
@@ -343,3 +344,3 @@ hogeHoge: 'value', | ||
beforeEach(() => { | ||
serverless.service.stepFunctions = { | ||
serverless.service.stepFunctions.stateMachines = { | ||
helloHello: 'value', | ||
@@ -346,0 +347,0 @@ hogeHoge: 'value', |
{ | ||
"name": "serverless-step-functions", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "The module is AWS Step Functions plugin for Serverless Framework", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,2 @@ | ||
[![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) | ||
[![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) | ||
# Serverless Step Functions (BETA) | ||
@@ -21,3 +21,3 @@ Serverless plugin for AWS Step Functions. | ||
Write definitions yaml using Amazon States Language in a `stepFunctions` statement in serverless.yml. | ||
`Resource` statements refer to `functions` statements. Therefore, you do not need to write a function arn directly. | ||
`Resource` statements refer to `functions` or `activities` statements. Therefore, you do not need to write a function arn or activity arn directly. | ||
Of course, you can also specify arn directly. | ||
@@ -32,10 +32,20 @@ | ||
stateMachines: | ||
hellostepfunc: | ||
hellostepfunc1: | ||
Comment: "A Hello World example of the Amazon States Language using an AWS Lambda Function" | ||
StartAt: HelloWorld | ||
StartAt: HelloWorld1 | ||
States: | ||
HelloWorld: | ||
HelloWorld1: | ||
Type: Task | ||
Resource: hellofunc | ||
End: true | ||
hellostepfunc2: | ||
StartAt: HelloWorld2 | ||
States: | ||
HelloWorld2: | ||
Type: Task | ||
Resource: myTask | ||
End: true | ||
activities: | ||
- myTask | ||
- yourTask | ||
``` | ||
@@ -45,3 +55,3 @@ | ||
### deploy | ||
#### All StateMachines deploy | ||
#### All StateMachines and Activities deploy | ||
``` | ||
@@ -51,13 +61,42 @@ $ sls deploy stepf | ||
##### options | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
#### All StateMachines deploy | ||
``` | ||
$ sls deploy stepf statemachines | ||
``` | ||
##### options | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
#### Single StateMachine deploy | ||
``` | ||
$ sls deploy stepf --state <stepfunctionname> | ||
$ sls deploy stepf statemachines --name <stepfunctionname> | ||
``` | ||
##### options | ||
- --name or -n The name of the step function in your service that you want to deploy. | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
#### options | ||
#### All Activities deploy | ||
``` | ||
$ sls deploy stepf activities | ||
``` | ||
- --state or -t The name of the step function in your service that you want to deploy. | ||
##### options | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
#### Single Activity deploy | ||
``` | ||
$ sls deploy stepf activities --name <activityname> | ||
``` | ||
##### options | ||
- --name or -n The name of the step function in your service that you want to deploy. | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
### invoke | ||
@@ -76,3 +115,3 @@ #### options | ||
### remove | ||
#### All StateMachines remove | ||
#### All StateMachines and Activities remove | ||
@@ -83,2 +122,15 @@ ``` | ||
##### options | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
#### All StateMachines remove | ||
``` | ||
$ sls remove stepf statemachines | ||
``` | ||
##### options | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
#### Single StateMachine remove | ||
@@ -96,2 +148,21 @@ | ||
#### All Activities remove | ||
``` | ||
$ sls remove stepf activities | ||
``` | ||
##### options | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
#### Single Activity remove | ||
``` | ||
$ sls remove stepf activities --name <activityname> | ||
``` | ||
##### options | ||
- --name or -n The name of the step function in your service that you want to deploy. | ||
- --stage or -s The stage in your service you want to deploy your step function. | ||
- --region or -r The region in your stage that you want to deploy your step function. | ||
## Sample statemachines setting in serverless.yml | ||
@@ -98,0 +169,0 @@ ### Waite State |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
125677
21
2708
356
0