-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from HyperBrain/function-deploy
Support serverless deploy function
- Loading branch information
Showing
4 changed files
with
3,449 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
|
||
const BbPromise = require("bluebird"); | ||
|
||
module.exports = { | ||
|
||
updateFunctionAlias() { | ||
this._serverless.cli.log('Updating function alias...'); | ||
|
||
const func = this.serverless.service.getFunction(this.options.function); | ||
|
||
// Publish the yet deployed $LATEST uploaded by Serverless and label it. | ||
|
||
return BbPromise.try(() => { | ||
// Get the hash of the deployed function package | ||
const params = { | ||
FunctionName: func.name, | ||
Qualifier: "$LATEST" | ||
}; | ||
|
||
return this.provider.request( | ||
'Lambda', | ||
'getFunction', | ||
params, | ||
this.options.stage, this.options.region | ||
); | ||
}) | ||
.then(result => { | ||
// Publish $LATEST | ||
const sha256 = result.Configuration.CodeSha256; | ||
const params = { | ||
FunctionName: func.name, | ||
CodeSha256: sha256, | ||
Description: "Deployed manually" | ||
}; | ||
return this.provider.request( | ||
'Lambda', | ||
'publishVersion', | ||
params, | ||
this.options.stage, this.options.region | ||
); | ||
}) | ||
.then(result => { | ||
// Label it | ||
const version = result.Version; | ||
const params = { | ||
FunctionName: func.name, | ||
Name: this._alias, | ||
FunctionVersion: version, | ||
Description: 'Deployed manually' | ||
}; | ||
return this.provider.request( | ||
'Lambda', | ||
'updateAlias', | ||
params, | ||
this.options.stage, this.options.region | ||
); | ||
}) | ||
.then(result => { | ||
this.serverless.cli.log(`Successfully updated alias: ${this.options.function}@${this._alias} -> ${result.FunctionVersion}`); | ||
return BbPromise.resolve(); | ||
}); | ||
} | ||
|
||
}; |
Oops, something went wrong.