Skip to content

Commit 740738e

Browse files
committed
third commit
1 parent dc053e1 commit 740738e

File tree

1 file changed

+68
-40
lines changed

1 file changed

+68
-40
lines changed

lib/index.js

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,28 @@ class AwsStepFunctionsDeploy {
99
this.options = options;
1010
this.provider = this.serverless.getProvider('aws');
1111
this.awsStateLanguage = {};
12+
this.commands = {
13+
deploy: {
14+
commands: {
15+
stepf: {
16+
usage: 'Deploy Step functions',
17+
lifecycleEvents: [
18+
'deploy'
19+
],
20+
options: {
21+
statemachine: {
22+
usage: 'Name of the State Machine',
23+
shortcut: 'sm',
24+
required: true,
25+
}
26+
}
27+
}
28+
}
29+
}
30+
};
1231

1332
this.hooks = {
14-
'before:deploy:deploy': this.action.bind(this),
33+
'deploy:stepf:deploy': this.action.bind(this),
1534
};
1635
}
1736

@@ -48,53 +67,62 @@ class AwsStepFunctionsDeploy {
4867
if (!this.stepFunctions) {
4968
return BbPromise.resolve();
5069
}
51-
52-
53-
_.forEach(this.stepFunctions, function (stateMachine, stateMachineName) {
54-
if (!stateMachine.start) {
55-
const errorMessage = [
56-
' Please set `start` in stepFunctions statements in serverless.yml .',
57-
].join('');
58-
throw new this.serverless.classes
59-
.Error(errorMessage);
60-
}
61-
62-
//@todo error handling to not stateMachine.states
63-
64-
const StartAt = stateMachine.start;
65-
const Comment = stateMachine.comment;
66-
this.awsStateLanguage[stateMachineName] = {
67-
Comment: Comment || 'Step Functions Generated by Serverless Step Functions.',
68-
StartAt,
69-
States: {},
70-
};
7170

72-
_.forEach(stateMachine.states, function (state) {
73-
//@todo error handling to not type and resource
74-
const Type = state.type;
75-
const Resource = state.resource;
76-
this.awsStateLanguage[stateMachineName].States = {
77-
Type,
78-
Resource,
79-
End: 'true'
80-
}
81-
});
82-
});
71+
if (typeof this.stepFunctions[this.options.statemachine] === 'undefined') {
72+
const errorMessage = [
73+
`Step function "${this.options.statemachine}" is not exists`,
74+
].join('');
75+
throw new this.serverless.classes
76+
.Error(errorMessage);
77+
}
8378

79+
//@todo get lambda arn from functionname
80+
this.awsStateLanguage[this.options.statemachine] = JSON.stringify(this.stepFunctions[this.options.statemachine]);
8481
return BbPromise.resolve();
8582
}
8683

8784
deploy() {
88-
return this.provider.request('StepFunctions',
89-
'createStateMachine',
90-
{
91-
definition: 'STRING_VALUE',
92-
name: 'STRING_VALUE',
93-
roleArn: 'STRING_VALUE'
94-
},
85+
let stateMachineArn;
86+
87+
return this.provider.request('STS',
88+
'getCallerIdentity',
89+
{},
9590
this.options.stage,
96-
this.options.region);
91+
this.options.region)
92+
.then((result) => {
93+
const region = this.options.region || 'us-east-1';
94+
stateMachineArn = `arn:aws:states:${region}:${result.Account}:stateMachine:${this.options.statemachine}`;
95+
}).then((result) => {
96+
return this.provider.request('StepFunctions',
97+
'describeStateMachine',
98+
{
99+
stateMachineArn
100+
},
101+
this.options.stage,
102+
this.options.region);
103+
}).then((result) => {
104+
console.log(result)
105+
return this.provider.request('StepFunctions',
106+
'deleteStateMachine',
107+
{
108+
stateMachineArn
109+
},
110+
this.options.stage,
111+
this.options.region);
97112

113+
}).then((result) => {
114+
return this.provider.request('StepFunctions',
115+
'createStateMachine',
116+
{
117+
definition: this.awsStateLanguage[this.options.statemachine],
118+
name: this.options.statemachine,
119+
roleArn: ''
120+
},
121+
this.options.stage,
122+
this.options.region)
123+
}).catch((error) => {
124+
console.log(error);
125+
});
98126
}
99127

100128
}

0 commit comments

Comments
 (0)