Skip to content

Commit

Permalink
Refactor setup of function versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Dec 4, 2019
1 parent 4c1cee3 commit 937cd92
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions lib/plugins/aws/package/compile/functions/index.js
Expand Up @@ -409,6 +409,11 @@ class AwsCompileFunctions {
}
}

const versionFunction =
functionObject.versionFunction != null
? functionObject.versionFunction
: this.serverless.service.provider.versionFunctions;

if (functionObject.provisionedConcurrency) {
const provisionedConcurrency = _.parseInt(functionObject.provisionedConcurrency);

Expand Down Expand Up @@ -449,8 +454,6 @@ class AwsCompileFunctions {
newFunctionObject
);

const newVersion = this.cfLambdaVersionTemplate();

// Create hashes for the artifact and the logical id of the version resource
// The one for the version resource must include the function configuration
// to make sure that a new version is created on configuration changes and
Expand Down Expand Up @@ -490,6 +493,10 @@ class AwsCompileFunctions {
const fileDigest = fileHash.read();
const versionDigest = versionHash.read();

if (!versionFunction) return;

const newVersion = this.cfLambdaVersionTemplate();

newVersion.Properties.CodeSha256 = fileDigest;
newVersion.Properties.FunctionName = { Ref: functionLogicalId };
if (functionObject.description) {
Expand All @@ -506,17 +513,10 @@ class AwsCompileFunctions {
[versionLogicalId]: newVersion,
};

const versionFunction =
functionObject.versionFunction != null
? functionObject.versionFunction
: this.serverless.service.provider.versionFunctions;

if (versionFunction) {
_.merge(
this.serverless.service.provider.compiledCloudFormationTemplate.Resources,
newVersionObject
);
}
_.merge(
this.serverless.service.provider.compiledCloudFormationTemplate.Resources,
newVersionObject
);

// Add function versions to Outputs section
const functionVersionOutputLogicalId = this.provider.naming.getLambdaVersionOutputLogicalId(
Expand All @@ -526,13 +526,9 @@ class AwsCompileFunctions {

newVersionOutput.Value = { Ref: versionLogicalId };

if (versionFunction) {
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Outputs, {
[functionVersionOutputLogicalId]: newVersionOutput,
});
}

return BbPromise.resolve();
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Outputs, {
[functionVersionOutputLogicalId]: newVersionOutput,
});
});
}

Expand Down

0 comments on commit 937cd92

Please sign in to comment.