Skip to content

Commit 6b5d7ca

Browse files
Merge pull request #343 from DmytroKucheryavenko/master
feat: retain config
2 parents 78604f4 + e9d2031 commit 6b5d7ca

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

README.md

+12
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

+4
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

+2
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

+18
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
});

0 commit comments

Comments
 (0)