Skip to content

Commit 163e6c1

Browse files
Merge branch 'master' into patch-1
2 parents a544ffc + 70edc57 commit 163e6c1

8 files changed

+56
-25
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This is the Serverless Framework plugin for AWS Step Functions.
1111
- [Adding a custom name for a state machine](#adding-a-custom-name-for-a-statemachine)
1212
- [Adding a custom logical id for a stateMachine](#adding-a-custom-logical-id-for-a-statemachine)
1313
- [Depending on another logical id](#depending-on-another-logical-id)
14+
- [Adding retain property for a state machine](#adding-retain-property-for-a-statemachine)
1415
- [CloudWatch Alarms](#cloudwatch-alarms)
1516
- [CloudWatch Notifications](#cloudwatch-notifications)
1617
- [Blue-Green deployments](#blue-green-deployment)
@@ -219,6 +220,17 @@ stepFunctions:
219220
- myOtherDB
220221
- myStream
221222
```
223+
### Adding retain property for a stateMachine
224+
There are some practical cases when you would like to prevent state machine from deletion on stack delete or update. This can be achieved by adding `retain` property to the state machine section.
225+
226+
```yaml
227+
stepFunctions:
228+
stateMachines:
229+
myStateMachine:
230+
retain: true
231+
```
232+
233+
Configuring in such way adds `"DeletionPolicy" : "Retain"` to the state machine within CloudFormation template.
222234
223235
### CloudWatch Alarms
224236

lib/deploy/stepFunctions/compileStateMachines.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ module.exports = {
224224
[stateMachineLogicalId]: stateMachineTemplate,
225225
};
226226

227+
if (stateMachineObj.retain) {
228+
newStateMachineObject[stateMachineLogicalId].DeletionPolicy = 'Retain';
229+
}
230+
227231
if (stateMachineObj.name) {
228232
newStateMachineObject[
229233
stateMachineLogicalId].Properties.StateMachineName = stateMachineObj.name;

lib/deploy/stepFunctions/compileStateMachines.schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const alarms = Joi.object();
4242
const notifications = Joi.object();
4343
const useExactVersion = Joi.boolean().default(false);
4444
const type = Joi.string().valid('STANDARD', 'EXPRESS').default('STANDARD');
45+
const retain = Joi.boolean().default(false);
4546

4647
const schema = Joi.object().keys({
4748
id,
@@ -55,6 +56,7 @@ const schema = Joi.object().keys({
5556
alarms,
5657
notifications,
5758
type,
59+
retain,
5860
loggingConfig,
5961
inheritGlobalTags,
6062
});

lib/deploy/stepFunctions/compileStateMachines.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,4 +1430,22 @@ describe('#compileStateMachines', () => {
14301430
expect(Object.keys(serverlessStepFunctions.serverless.service.provider
14311431
.compiledCloudFormationTemplate.Outputs).length).to.equal(0);
14321432
});
1433+
1434+
it('should add DeletionPolicy when retain is true', () => {
1435+
serverless.service.stepFunctions = {
1436+
stateMachines: {
1437+
myStateMachine1: {
1438+
definition: 'definition1',
1439+
name: 'stateMachineBeta1',
1440+
retain: true,
1441+
},
1442+
},
1443+
};
1444+
1445+
serverlessStepFunctions.compileStateMachines();
1446+
1447+
expect(serverlessStepFunctions.serverless.service
1448+
.provider.compiledCloudFormationTemplate.Resources
1449+
.StateMachineBeta1.DeletionPolicy).to.equal('Retain');
1450+
});
14331451
});

lib/yamlParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
const serviceFileName = this.options.config || this.serverless.config.serverless.service.serviceFilename || 'serverless.yml';
1818
const serverlessYmlPath = path.join(servicePath, serviceFileName);
1919

20-
if (['.js', '.json'].includes(path.extname(serverlessYmlPath))) {
20+
if (['.js', '.json', '.ts'].includes(path.extname(serverlessYmlPath))) {
2121
parse = this.loadFromRequiredFile;
2222
} else {
2323
parse = fromYamlFile;

lib/yamlParser.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ describe('#yamlParse', () => {
148148
});
149149
});
150150

151+
it('should be able to load from a ts file', () => {
152+
serverless.config.serverless.service.serviceFilename = 'serverless.ts';
153+
const requireFileStub = sinon.stub(serverlessStepFunctions, 'loadFromRequiredFile')
154+
.returns(BbPromise.resolve({
155+
stepFunctions: {
156+
stateMachines: 'stepFunctions',
157+
activities: 'my-activity',
158+
},
159+
}));
160+
serverlessStepFunctions.yamlParse()
161+
.then(() => {
162+
expect(requireFileStub.calledOnce).to.be.equal(true);
163+
expect(serverless.service.stepFunctions.stateMachines).to.be.equal('stepFunctions');
164+
expect(serverless.service.stepFunctions.activities).to.be.equal('my-activity');
165+
});
166+
});
167+
151168
it('should create empty object when stepfunctions param are not given', () => {
152169
serverlessStepFunctions.serverless.yamlParser.parse.restore();
153170
serverlessStepFunctions.serverless.variables.populateObject.restore();

package-lock.json

Lines changed: 1 addition & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-step-functions",
3-
"version": "2.17.4",
3+
"version": "2.20.0",
44
"description": "The module is AWS Step Functions plugin for Serverless Framework",
55
"main": "lib/index.js",
66
"scripts": {
@@ -45,7 +45,6 @@
4545
"dependencies": {
4646
"@hapi/joi": "^15.0.2",
4747
"asl-validator": "^1.7.0",
48-
"aws-sdk": "^2.282.1",
4948
"bluebird": "^3.4.0",
5049
"chalk": "^1.1.1",
5150
"lodash": "^4.17.11",

0 commit comments

Comments
 (0)