mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
alias all
This commit is contained in:
parent
558e784c35
commit
aa753f8bf0
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
//TODO: add alias HIGHEST <alias> [paths|ALL]
|
||||
/**
|
||||
* Action: AliasLambda
|
||||
*/
|
||||
@ -47,10 +46,11 @@ class AliasLambda extends JawsPlugin {
|
||||
registerActions() {
|
||||
this.Jaws.action(this.lambdaCreateAlias.bind(this), {
|
||||
handler: 'lambdaCreateAlias',
|
||||
description: `Version lambda at CWD. Dont support aliasing multi lambdas at a time, because could be version mismatches
|
||||
usage: jaws lambda alias <version> <aliasName>`,
|
||||
description: `Create alias for lambda at CWD. If 'GREATEST' is specified for <version>, the highest version number for the lambda will be used.
|
||||
|
||||
usage: jaws lambda alias <version|GREATEST> <aliasName>`,
|
||||
context: 'lambda',
|
||||
contextAction: 'alias',
|
||||
contextAction: 'create-alias',
|
||||
options: [
|
||||
{
|
||||
option: 'stage',
|
||||
|
||||
@ -586,7 +586,11 @@ class DeployLambda extends JawsPlugin {
|
||||
this.Jaws.action(this.deployLambdas.bind(this), {
|
||||
handler: 'lambdaDeploy',
|
||||
description: `Deploy lambda at CWD, lambdas at specified paths, or ALL lambdas
|
||||
usage: jaws lambda deploy [options]... [paths|ALL]...`,
|
||||
usage: jaws lambda deploy [options]... [paths|ALL]...
|
||||
|
||||
ex:
|
||||
jaws lambda deploy ./aws_modules/greetings/hello
|
||||
jaws lambda deploy ALL`,
|
||||
context: 'lambda',
|
||||
contextAction: 'deploy',
|
||||
options: [
|
||||
@ -749,19 +753,11 @@ usage: jaws lambda deploy [options]... [paths|ALL]...`,
|
||||
* @private
|
||||
*/
|
||||
_setLambdaAwsmPaths(lambdaPaths) {
|
||||
let _this = this,
|
||||
deferred;
|
||||
|
||||
if (lambdaPaths[0].toLowerCase() == 'all') {
|
||||
JawsUtils.jawsDebug('all lambda paths specified, searching..');
|
||||
deferred = JawsUtils.findAllLambdas(_this.Jaws._projectRootPath);
|
||||
} else {
|
||||
deferred = JawsUtils.getFullLambdaPaths(process.cwd(), lambdaPaths);
|
||||
}
|
||||
|
||||
return deferred.then(fullAwsmJsonPaths => {
|
||||
_this._lambdaAwsmPathsToDeploy = fullAwsmJsonPaths;
|
||||
});
|
||||
let _this = this;
|
||||
return JawsUtils.resolveLambdaPaths(process.cwd(), this.Jaws._projectRootPath, lambdaPaths)
|
||||
.then(fullAwsmJsonPaths => {
|
||||
_this._lambdaAwsmPathsToDeploy = fullAwsmJsonPaths;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
//TODO: add version ALL
|
||||
|
||||
/**
|
||||
* Action: VersionLambda
|
||||
*/
|
||||
@ -11,7 +9,6 @@ const JawsPlugin = require('../../JawsPlugin'),
|
||||
JawsCLI = require('../../utils/cli'),
|
||||
BbPromise = require('bluebird'),
|
||||
path = require('path'),
|
||||
os = require('os'),
|
||||
AWSUtils = require('../../utils/aws'),
|
||||
JawsUtils = require('../../utils/index');
|
||||
|
||||
@ -48,7 +45,12 @@ class VersionLambda extends JawsPlugin {
|
||||
registerActions() {
|
||||
this.Jaws.action(this.lambdaPublishVersion.bind(this), {
|
||||
handler: 'lambdaPublishVersion',
|
||||
description: 'Version lambda at CWD or lambdas at specified paths',
|
||||
description: `Version lambda at CWD, lambdas at specified paths, or ALL lambdas
|
||||
usage: jaws lambda publish-version [options]... [paths|ALL]...
|
||||
|
||||
ex:
|
||||
jaws lambda publish-version ./aws_modules/greetings/hello
|
||||
jaws lambda publish-version ALL`,
|
||||
context: 'lambda',
|
||||
contextAction: 'publish-version',
|
||||
options: [
|
||||
@ -180,12 +182,14 @@ class VersionLambda extends JawsPlugin {
|
||||
*/
|
||||
_setLambdaLogicalIds(lambdaPaths) {
|
||||
let _this = this;
|
||||
return JawsUtils.getFullLambdaPaths(process.cwd(), lambdaPaths)
|
||||
return JawsUtils.resolveLambdaPaths(process.cwd(), this.Jaws._projectRootPath, lambdaPaths)
|
||||
.then(fullAwsmJsonPaths => {
|
||||
_this._lambdaLogicalIdsToVersion = fullAwsmJsonPaths.map(alp => {
|
||||
let awsmJson = JawsUtils.readAndParseJsonSync(alp);
|
||||
return JawsUtils.getLambdaName(awsmJson);
|
||||
});
|
||||
|
||||
JawsUtils.jawsDebug('setting _lambdaLogicalIdsToVersion', _this._lambdaLogicalIdsToVersion);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,6 +354,8 @@ exports.cfGetLambdaPhysicalsFromLogicals = function(logicalIds, lambdaResourceSu
|
||||
|
||||
lambdaPhysicalIds.push(foundLambda.PhysicalResourceId);
|
||||
}
|
||||
|
||||
return lambdaPhysicalIds;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -366,9 +368,10 @@ exports.cfGetLambdaPhysicalsFromLogicals = function(logicalIds, lambdaResourceSu
|
||||
exports.lambdaPublishVersions = function(awsProfile, awsRegion, functionNames) {
|
||||
this.configAWS(awsProfile, awsRegion);
|
||||
|
||||
let L = Promise.promisifyAll(new AWS.Lambda({
|
||||
apiVersion: '2015-03-31',
|
||||
}));
|
||||
let L = new AWS.Lambda({
|
||||
apiVersion: '2015-03-31',
|
||||
}),
|
||||
publishVersionAsync = Promise.promisify(L.publishVersion, L);
|
||||
|
||||
let d = new Date(),
|
||||
ds = `versioned at ${d}`,
|
||||
@ -380,7 +383,9 @@ exports.lambdaPublishVersions = function(awsProfile, awsRegion, functionNames) {
|
||||
Description: ds
|
||||
};
|
||||
|
||||
deferreds.push(L.publishVersionAsync(params));
|
||||
JawsUtils.jawsDebug('Pushing version to publish: ', params);
|
||||
|
||||
deferreds.push(publishVersionAsync(params));
|
||||
});
|
||||
|
||||
return Promise.all(deferreds)
|
||||
@ -388,6 +393,13 @@ exports.lambdaPublishVersions = function(awsProfile, awsRegion, functionNames) {
|
||||
return data.map(d => {
|
||||
return {FunctionName: d.FunctionName, Version: d.Version, FunctionArn: d.FunctionArn};
|
||||
});
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.code == 'ServiceUnavailableException') {
|
||||
console.error('ServiceUnavailableException when trying to version lambda. This could mean you have not deployed the lambda since last time you published a version.');
|
||||
}
|
||||
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
|
||||
@ -406,9 +418,10 @@ exports.lambdaPublishVersions = function(awsProfile, awsRegion, functionNames) {
|
||||
exports.lambdaCreateAlias = function(awsProfile, awsRegion, functionName, functionVersion, aliasName) {
|
||||
this.configAWS(awsProfile, awsRegion);
|
||||
|
||||
let L = Promise.promisifyAll(new AWS.Lambda({
|
||||
apiVersion: '2015-03-31',
|
||||
}));
|
||||
let L = new AWS.Lambda({
|
||||
apiVersion: '2015-03-31',
|
||||
}),
|
||||
createAliasAsync = Promise.promisify(L.createAlias, L);
|
||||
|
||||
let d = new Date(),
|
||||
params = {
|
||||
@ -418,7 +431,7 @@ exports.lambdaCreateAlias = function(awsProfile, awsRegion, functionName, functi
|
||||
Description: `aliased at ${d}`,
|
||||
};
|
||||
|
||||
return L.createAliasAsync(params)
|
||||
return createAliasAsync(params)
|
||||
.then(d => {
|
||||
return {AliasArn: d.AliasArn, FunctionVersion: d.FunctionVersion};
|
||||
});
|
||||
|
||||
@ -67,6 +67,25 @@ exports.findAllAwsmPathsOfType = function(startPath, type) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a list of paths to lambda dirs, will resolve to abs path (ex: ~,./).
|
||||
* If lambdaPaths[0] == 'all' will find all lambda paths
|
||||
* If lambdaPaths is empty or not set, will use lambda at cwd
|
||||
*
|
||||
* @param cwd
|
||||
* @param projectRootPath
|
||||
* @param lambdaPaths Array
|
||||
* @returns {Promise.<Array>} list of full paths to lambda.awsm.json files that are type lambda
|
||||
*/
|
||||
exports.resolveLambdaPaths = function(cwd, projectRootPath, lambdaPaths) {
|
||||
if (lambdaPaths[0].toLowerCase() == 'all') {
|
||||
this.jawsDebug('all lambda paths specified, searching..');
|
||||
return this.findAllLambdas(projectRootPath);
|
||||
} else {
|
||||
return this.getFullLambdaPaths(cwd, lambdaPaths);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Find project root path
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user