Skip to content

Commit 2ca98b0

Browse files
mcjfunkEnase
authored andcommitted
Option to retain versions
1 parent 93fe768 commit 2ca98b0

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ alias, this option should not be used.)
4444
From now on you can reference the aliased versions on Lambda invokes with the
4545
stage qualifier. The aliased version is read only in the AWS console, so it is
4646
guaranteed that the environment and function parameters (memory, etc.) cannot
47-
be changed for a deployed version by accident, as it can be done with the
47+
be changed for a deployed version by accident, as it can be done with the
4848
`$LATEST` qualifier.This adds an additional level of stability to your deployment
4949
process.
5050

@@ -68,6 +68,12 @@ Example:
6868

6969
See the `alias remove` command below.
7070

71+
## Maintain versions
72+
73+
By default, when you deploy, the version of the function gets assigned the retention policy of 'Delete'. This means any subsequent deploys will delete any version without an alias. This was done because you can no longer tell which alias it came from.
74+
75+
There are usecases where retaining versions is less risky and as such, you can opt into retaining these versions by deploying with the `--retain` flag.
76+
7177
## Remove a service
7278

7379
To remove a complete service, all deployed user aliases have to be removed first,

lib/stackops/functions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
110110

111111
// Reference correct function name in version
112112
version.Properties.FunctionName = { 'Fn::ImportValue': `${stackName}-${functionName}-LambdaFunctionArn` };
113-
// With alias support we do not want to retain the versions
114-
version.DeletionPolicy = 'Delete';
113+
114+
// With alias support we do not want to retain the versions unless explicitly asked to do so
115+
version.DeletionPolicy = this._retain ? 'Retain' : 'Delete';
115116

116117
// Add alias to alias stack. Reference the version export in the stage stack
117118
// to prevent version deletion.

lib/validate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020
this._masterAlias = this._options.masterAlias || this._stage;
2121
this._alias = this._options.alias || this._masterAlias;
2222
this._stackName = this._provider.naming.getStackName();
23+
this._retain = this._options.retain || false;
2324

2425
// Make alias available as ${self:provider.alias}
2526
this._serverless.service.provider.alias = this._alias;

0 commit comments

Comments
 (0)