mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
merged v0.5 into 0.5-serializers
This commit is contained in:
commit
c48e8db98d
@ -15,10 +15,10 @@
|
||||
"./actions/EndpointBuildApiGateway.js",
|
||||
"./actions/EndpointRun.js",
|
||||
"./actions/EventDeploy.js",
|
||||
"./actions/EventDeployStreamLambda.js",
|
||||
"./actions/EventDeployS3Lambda.js",
|
||||
"./actions/EventDeploySNSLambda.js",
|
||||
"./actions/EventDeployScheduledLambda.js",
|
||||
"./actions/EventLambdaStream.js",
|
||||
"./actions/EventLambdaS3.js",
|
||||
"./actions/EventLambdaSNS.js",
|
||||
"./actions/EventLambdaSchedule.js",
|
||||
"./actions/DashDeploy.js",
|
||||
"./actions/DashSummary.js",
|
||||
"./actions/EndpointDeployApiGateway.js",
|
||||
|
||||
@ -190,4 +190,4 @@ class Function extends SerializerFileSystem {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Function;
|
||||
module.exports = Function;
|
||||
@ -60,27 +60,25 @@ class ServerlessProviderAws {
|
||||
*/
|
||||
|
||||
request(service, method, params, stage, region, options) {
|
||||
let _this = this;
|
||||
let _this = this;
|
||||
let awsService = new this.sdk[service](_this.getCredentials(stage, region));
|
||||
let req = awsService[method](params);
|
||||
let req = awsService[method](params);
|
||||
|
||||
// Add listeners...
|
||||
//req.on('validate', function(r) {});
|
||||
req.on('validate', function (r) {
|
||||
});
|
||||
|
||||
let performRequest = function() {
|
||||
return new BbPromise(function(resolve, reject) {
|
||||
req.send(function(err, data) {
|
||||
if (err && err.statusCode == 429) {
|
||||
SUtils.sDebug("'Too many requests' received, sleeping 5 seconds, then retrying...");
|
||||
setTimeout( performRequest, 5000 );
|
||||
} else if (err) {
|
||||
reject( err );
|
||||
return SUtils.persistentRequest(function () {
|
||||
return new BbPromise(function (resolve, reject) {
|
||||
req.send(function (err, data) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
};
|
||||
return performRequest();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,6 +141,14 @@ class ServerlessProviderAws {
|
||||
sessionToken: process.env['AWS_SESSION_TOKEN'],
|
||||
region: region
|
||||
};
|
||||
} else if (this._S.config.awsAdminKeyId) {
|
||||
|
||||
// Access Keys from the config
|
||||
credentials = {
|
||||
accessKeyId: this._S.config.awsAdminKeyId,
|
||||
secretAccessKey: this._S.config.awsAdminSecretKey,
|
||||
region: region
|
||||
};
|
||||
}
|
||||
|
||||
if (!credentials) {
|
||||
|
||||
@ -56,6 +56,10 @@ class Stage extends SerializerFileSystem {
|
||||
this.regions[ region.getName() ] = region;
|
||||
}
|
||||
|
||||
destroy(){
|
||||
|
||||
}
|
||||
|
||||
removeRegion( name ){
|
||||
let region = this.regions[ name ];
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird'),
|
||||
Zip = require('node-zip'),
|
||||
@ -166,20 +166,22 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
SUtils.sDebug(`"${_this.evt.options.stage} - ${_this.evt.options.region} - ${_this.functionName}": Uploading lambda zip to project bucket...`);
|
||||
|
||||
let d = new Date(),
|
||||
s3Bucket = _this.meta.variables.projectBucket,
|
||||
s3Region = s3Bucket.split('.')[1],
|
||||
key = ['serverless', _this.project.name, _this.evt.options.stage, 'lambdas', _this.functionName + '@' + d.getTime() + '.zip'].join('/'),
|
||||
params = {
|
||||
Bucket: _this.meta.variables.projectBucket,
|
||||
Bucket: s3Bucket,
|
||||
Key: key,
|
||||
ACL: 'private',
|
||||
ContentType: 'application/zip',
|
||||
Body: fs.createReadStream(_this.pathCompressed)
|
||||
};
|
||||
|
||||
return _this.aws.request('S3', 'upload', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
return _this.aws.request('S3', 'upload', params, _this.evt.options.stage, s3Region)
|
||||
.then(function (s3Key) {
|
||||
|
||||
// Store S3 Data
|
||||
_this.s3Bucket = _this.meta.variables.projectBucket;
|
||||
_this.s3Bucket = s3Bucket;
|
||||
_this.s3Key = s3Key;
|
||||
|
||||
});
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird'),
|
||||
fs = require('fs'),
|
||||
@ -173,6 +173,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
);
|
||||
|
||||
let key = ['serverless', _this.project.name, _this.evt.options.stage, _this.evt.options.region, 'envVars', '.env'].join('/'),
|
||||
s3Region = _this.meta.variables.projectBucket.split('.')[1],
|
||||
params = {
|
||||
Bucket: _this.meta.variables.projectBucket,
|
||||
Key: key
|
||||
@ -181,7 +182,9 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
SUtils.sDebug(`Getting ENV Vars: ${_this.meta.variables.projectBucket} - ${key}`);
|
||||
|
||||
// Get ENV file from S3
|
||||
return _this.aws.request('S3', 'getObject', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
let NoSuchKey = {code: 'NoSuchKey'};
|
||||
return _this.aws.request('S3', 'getObject', params, _this.evt.options.stage, s3Region)
|
||||
.catch(NoSuchKey => ({Body: ''}))
|
||||
.then(function(s3ObjData) {
|
||||
|
||||
fs.writeFileSync(
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils')),
|
||||
BbPromise = require('bluebird'),
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
@ -155,11 +155,6 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
return BbPromise.reject(new SError('Sorry, this is only available in interactive mode'));
|
||||
}
|
||||
|
||||
// Get all functions in CWD
|
||||
let sPath = _this.getSPathFromCwd(_this.S.getProject().getRootPath());
|
||||
|
||||
_this.components = _this.S.getProject().getAllComponents( sPath ? {} : { paths: [sPath] });
|
||||
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
@ -170,31 +165,30 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
_prompt() {
|
||||
|
||||
let _this = this,
|
||||
data = {};
|
||||
sPath = _this.getSPathFromCwd(_this.S.getProject().getRootPath());
|
||||
|
||||
// Prepare function & endpoints choices
|
||||
let choices = [];
|
||||
_.each( _this.components, function(component){
|
||||
_.each( component.getAllFunctions(), function(func){
|
||||
// Push function sPath as spacer
|
||||
choices.push({
|
||||
spacer: func.getSPath()
|
||||
});
|
||||
|
||||
_.each( _this.S.getProject().getAllFunctions( sPath ? { paths: [sPath] } : {}), function(func){
|
||||
// Push function sPath as spacer
|
||||
choices.push({
|
||||
spacer: func.getSPath()
|
||||
});
|
||||
|
||||
choices.push({
|
||||
key: ' ',
|
||||
value: func.getSPath(),
|
||||
label: 'function - ' + func.getSPath(),
|
||||
type: 'function'
|
||||
});
|
||||
|
||||
_.each( func.getAllEndpoints(), function(endpoint){
|
||||
choices.push({
|
||||
key: ' ',
|
||||
value: func.getSPath(),
|
||||
label: 'function - ' + func.getSPath(),
|
||||
type: 'function'
|
||||
});
|
||||
|
||||
_.each( func.getAllEndpoints(), function(endpoint){
|
||||
choices.push({
|
||||
key: ' ',
|
||||
value: endpoint.getSPath(),
|
||||
label: 'endpoint - ' + endpoint.getSPath(),
|
||||
type: 'endpoint'
|
||||
});
|
||||
value: endpoint.getSPath(),
|
||||
label: 'endpoint - ' + endpoint.getSPath(),
|
||||
type: 'endpoint'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird'),
|
||||
async = require('async'),
|
||||
@ -262,7 +262,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
};
|
||||
|
||||
// List all Resources for this REST API
|
||||
return SUtils.persistentRequest(function() { return _this.aws.request('APIGateway', 'getResources', params, _this.evt.options.stage, _this.evt.options.region); })
|
||||
return _this.aws.request('APIGateway', 'getResources', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
.then(function(response) {
|
||||
_this.apiResources = response.items;
|
||||
|
||||
@ -393,7 +393,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
};
|
||||
|
||||
// Create Resource
|
||||
return SUtils.persistentRequest(function() { return _this.aws.request('APIGateway', 'createResource', params, _this.evt.options.stage, _this.evt.options.region); } )
|
||||
return _this.aws.request('APIGateway', 'createResource', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
.then(function(response) {
|
||||
|
||||
// Save resource
|
||||
@ -444,7 +444,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
restApiId: _this.restApi.id /* required */
|
||||
};
|
||||
|
||||
return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'getMethod', params, _this.evt.options.stage, _this.evt.options.region); } )
|
||||
return _this.aws.request('APIGateway', 'getMethod', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
.then(function(response) {
|
||||
|
||||
// Method exists. Delete and recreate it.
|
||||
@ -460,7 +460,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
restApiId: _this.restApi.id /* required */
|
||||
};
|
||||
|
||||
return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'deleteMethod', params, _this.evt.options.stage, _this.evt.options.region); } )
|
||||
return _this.aws.request('APIGateway', 'deleteMethod', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
.then(function(response) {
|
||||
let params = {
|
||||
authorizationType: _this.endpoint.authorizationType, /* required */
|
||||
@ -472,7 +472,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
requestParameters: requestParameters
|
||||
};
|
||||
|
||||
return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'putMethod', params, _this.evt.options.stage, _this.evt.options.region); } )
|
||||
return _this.aws.request('APIGateway', 'putMethod', params, _this.evt.options.stage, _this.evt.options.region);
|
||||
|
||||
});
|
||||
}, function(error) {
|
||||
@ -489,7 +489,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
requestParameters: requestParameters
|
||||
};
|
||||
|
||||
return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'putMethod', params, _this.evt.options.stage, _this.evt.options.region); } );
|
||||
return _this.aws.request('APIGateway', 'putMethod', params, _this.evt.options.stage, _this.evt.options.region);
|
||||
})
|
||||
.then(function(response) {
|
||||
|
||||
@ -569,7 +569,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
};
|
||||
|
||||
// Create Integration
|
||||
return SUtils.persistentRequest( function() { return _this.aws.request('APIGateway', 'putIntegration', params, _this.evt.options.stage, _this.evt.options.region); } )
|
||||
return _this.aws.request('APIGateway', 'putIntegration', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
.then(function(response) {
|
||||
|
||||
// Save integration
|
||||
@ -639,7 +639,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
};
|
||||
|
||||
// Create Method Response
|
||||
return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'putMethodResponse', params, _this.evt.options.stage, _this.evt.options.region); } )
|
||||
return _this.aws.request('APIGateway', 'putMethodResponse', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
.then(function() {
|
||||
|
||||
SUtils.sDebug(
|
||||
@ -695,7 +695,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
};
|
||||
|
||||
// Create Integration Response
|
||||
return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'putIntegrationResponse', params, _this.evt.options.stage, _this.evt.options.region); } )
|
||||
return _this.aws.request('APIGateway', 'putIntegrationResponse', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
.then(function() {
|
||||
|
||||
SUtils.sDebug(
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird'),
|
||||
fs = require('fs');
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
chalk = require('chalk'),
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
chalk = require('chalk'),
|
||||
BbPromise = require('bluebird'),
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
SUtils = require(path.join(serverlessPath, 'utils'));
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
SUtils = require(path.join(serverlessPath, 'utils'));
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
@ -246,13 +246,13 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
};
|
||||
|
||||
if(eventType === 'dynamodbstream' || eventType === 'kinesisstream') {
|
||||
subAction = 'eventDeployStreamLambda';
|
||||
subAction = 'eventLambdaStream';
|
||||
} else if (eventType === 's3') {
|
||||
subAction = 'eventDeployS3Lambda';
|
||||
subAction = 'eventLambdaS3';
|
||||
} else if (eventType === 'sns') {
|
||||
subAction = 'eventDeploySNSLambda';
|
||||
subAction = 'eventLambdaSNS';
|
||||
} else if (eventType === 'schedule') {
|
||||
subAction = 'eventDeployScheduledLambda';
|
||||
subAction = 'eventLambdaSchedule';
|
||||
}
|
||||
|
||||
return _this.S.actions[subAction](newEvt)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* EventDeployS3Lambda:
|
||||
* EventLambdaS3:
|
||||
* Deploys an S3 based event sources.
|
||||
*
|
||||
* Options:
|
||||
@ -13,25 +13,25 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird');
|
||||
|
||||
|
||||
class EventDeployS3Lambda extends SPlugin {
|
||||
class EventLambdaS3 extends SPlugin {
|
||||
|
||||
constructor(S, config) {
|
||||
super(S, config);
|
||||
}
|
||||
|
||||
static getName() {
|
||||
return 'serverless.core.' + EventDeployS3Lambda.name;
|
||||
return 'serverless.core.' + EventLambdaS3.name;
|
||||
}
|
||||
|
||||
registerActions() {
|
||||
|
||||
this.S.addAction(this.eventDeployS3Lambda.bind(this), {
|
||||
handler: 'eventDeployS3Lambda',
|
||||
this.S.addAction(this.eventLambdaS3.bind(this), {
|
||||
handler: 'eventLambdaS3',
|
||||
description: 'Deploy an S3 event source'
|
||||
});
|
||||
|
||||
@ -42,7 +42,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
* Code Package Lambda
|
||||
*/
|
||||
|
||||
eventDeployS3Lambda(evt) {
|
||||
eventLambdaS3(evt) {
|
||||
let _this = this;
|
||||
_this.evt = evt;
|
||||
|
||||
@ -82,7 +82,8 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
};
|
||||
return _this.aws.request('Lambda', 'addPermission', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
})
|
||||
.then(function(data) {
|
||||
.then(function() {
|
||||
let s3Region = _this.S.state.getMeta().variables.projectBucket.split('.')[1];
|
||||
let params = {
|
||||
Bucket: populatedEvent.config.bucket,
|
||||
NotificationConfiguration: {
|
||||
@ -94,7 +95,23 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
]
|
||||
}
|
||||
};
|
||||
return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
|
||||
if (populatedEvent.config.filterRules) {
|
||||
let filterRules = populatedEvent.config.filterRules.map(function(rule){
|
||||
return {
|
||||
Name: rule.name,
|
||||
Value: rule.value
|
||||
}
|
||||
});
|
||||
|
||||
params.NotificationConfiguration.LambdaFunctionConfigurations[0].Filter = {
|
||||
Key: {
|
||||
FilterRules: filterRules
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, s3Region);
|
||||
})
|
||||
.then(function(data) {
|
||||
|
||||
@ -106,5 +123,5 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
}
|
||||
|
||||
|
||||
return( EventDeployS3Lambda );
|
||||
return( EventLambdaS3 );
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* EventDeploySNSLambda:
|
||||
* EventLambdaSNS:
|
||||
* Deploys an SNS based event sources. Subscribes a lambda to an SNS topic.
|
||||
*
|
||||
* Options:
|
||||
@ -13,36 +13,33 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird');
|
||||
|
||||
|
||||
class EventDeploySNSLambda extends SPlugin {
|
||||
class EventLambdaSNS extends SPlugin {
|
||||
|
||||
constructor(S, config) {
|
||||
super(S, config);
|
||||
}
|
||||
|
||||
static getName() {
|
||||
return 'serverless.core.' + EventDeploySNSLambda.name;
|
||||
return 'serverless.core.' + EventLambdaSNS.name;
|
||||
}
|
||||
|
||||
registerActions() {
|
||||
|
||||
this.S.addAction(this.eventDeploySNSLambda.bind(this), {
|
||||
handler: 'eventDeploySNSLambda',
|
||||
this.S.addAction(this.eventLambdaSNS.bind(this), {
|
||||
handler: 'eventLambdaSNS',
|
||||
description: 'Deploy an SNS event source. Subscribes the function to an SNS topic.'
|
||||
});
|
||||
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Event Deploy SNS Lambda
|
||||
*/
|
||||
|
||||
eventDeploySNSLambda(evt) {
|
||||
eventLambdaSNS(evt) {
|
||||
let _this = this;
|
||||
_this.evt = evt;
|
||||
|
||||
@ -98,5 +95,5 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
}
|
||||
}
|
||||
|
||||
return( EventDeploySNSLambda );
|
||||
return( EventLambdaSNS );
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* EventDeployScheduledLambda:
|
||||
* EventLambdaSchedule:
|
||||
* Deploys a Schedule based event source. Allows for scheduling lambda functions.
|
||||
*
|
||||
* Options:
|
||||
@ -13,36 +13,33 @@
|
||||
module.exports = function (SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird');
|
||||
|
||||
|
||||
class EventDeployScheduledLambda extends SPlugin {
|
||||
class EventLambdaSchedule extends SPlugin {
|
||||
|
||||
constructor(S, config) {
|
||||
super(S, config);
|
||||
}
|
||||
|
||||
static getName() {
|
||||
return 'serverless.core.' + EventDeployScheduledLambda.name;
|
||||
return 'serverless.core.' + EventLambdaSchedule.name;
|
||||
}
|
||||
|
||||
registerActions() {
|
||||
|
||||
this.S.addAction(this.eventDeployScheduledLambda.bind(this), {
|
||||
handler: 'eventDeployScheduledLambda',
|
||||
this.S.addAction(this.eventLambdaSchedule.bind(this), {
|
||||
handler: 'eventLambdaSchedule',
|
||||
description: 'Deploy a schedule based event source'
|
||||
});
|
||||
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Event Deploy Scheduled Lambda
|
||||
*/
|
||||
|
||||
eventDeployScheduledLambda(evt) {
|
||||
eventLambdaSchedule(evt) {
|
||||
let _this = this;
|
||||
_this.evt = evt;
|
||||
|
||||
@ -113,6 +110,10 @@ module.exports = function (SPlugin, serverlessPath) {
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
if (populatedEvent.config.input) {
|
||||
params.Targets[0].input = JSON.stringify(populatedEvent.config.input);
|
||||
}
|
||||
return _this.aws.request('CloudWatchEvents', 'putTargets', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
.then(function(data){
|
||||
return BbPromise.resolve(data);
|
||||
@ -121,5 +122,5 @@ module.exports = function (SPlugin, serverlessPath) {
|
||||
}
|
||||
}
|
||||
|
||||
return ( EventDeployScheduledLambda );
|
||||
return ( EventLambdaSchedule );
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
/**
|
||||
* EventDeployStreamLambda:
|
||||
* EventLambdaStream:
|
||||
* Deploys a Stream based event sources (dynamoDB & Kinesis).
|
||||
*
|
||||
* Options:
|
||||
@ -14,25 +14,25 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird');
|
||||
|
||||
|
||||
class EventDeployStreamLambda extends SPlugin {
|
||||
class EventLambdaStream extends SPlugin {
|
||||
|
||||
constructor(S, config) {
|
||||
super(S, config);
|
||||
}
|
||||
|
||||
static getName() {
|
||||
return 'serverless.core.' + EventDeployStreamLambda.name;
|
||||
return 'serverless.core.' + EventLambdaStream.name;
|
||||
}
|
||||
|
||||
registerActions() {
|
||||
|
||||
this.S.addAction(this.eventDeployStreamLambda.bind(this), {
|
||||
handler: 'eventDeployStreamLambda',
|
||||
this.S.addAction(this.eventLambdaStream.bind(this), {
|
||||
handler: 'eventLambdaStream',
|
||||
description: 'Deploy a stream based event source'
|
||||
});
|
||||
|
||||
@ -43,7 +43,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
* Deploy Stream Event
|
||||
*/
|
||||
|
||||
eventDeployStreamLambda(evt) {
|
||||
eventLambdaStream(evt) {
|
||||
let _this = this;
|
||||
_this.evt = evt;
|
||||
|
||||
@ -103,5 +103,5 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
}
|
||||
|
||||
|
||||
return( EventDeployStreamLambda );
|
||||
return( EventLambdaStream );
|
||||
};
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
SUtils = require(path.join(serverlessPath, 'utils'));
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
@ -156,6 +156,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
return this.S.getProvider('aws')
|
||||
.request('Lambda', 'getAlias', params, this.evt.options.stage, this.evt.options.region)
|
||||
.bind(this)
|
||||
.then(reply => this.evt.data.version = reply.FunctionVersion)
|
||||
.then(this._getLogStreams)
|
||||
.then( logStreams => {
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
BbPromise = require('bluebird'),
|
||||
chalk = require('chalk'),
|
||||
SCli = require( path.join( serverlessPath, 'utils', 'cli'));
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils')),
|
||||
spawnSync = require('child_process').spawnSync,
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
URL = require('url'),
|
||||
Download = require('download'),
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
SUtils = require(path.join(serverlessPath, 'utils')),
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require( path.join( serverlessPath, 'ServerlessError' ) ),
|
||||
SError = require( path.join( serverlessPath, 'Error' ) ),
|
||||
SCli = require( path.join( serverlessPath, 'utils/cli' ) ),
|
||||
SUtils = require( path.join( serverlessPath, 'utils' ) ),
|
||||
BbPromise = require('bluebird'),
|
||||
@ -281,10 +281,8 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
_validateAndPrepare() {
|
||||
|
||||
this.S.getProvider('aws').getProfile(this.evt.options.profile);
|
||||
|
||||
// If Profile, extract API Keys
|
||||
if (this.evt.options.profile) {
|
||||
if (this.evt.options.profile && this.S.getProvider('aws').getProfile(this.evt.options.profile)) {
|
||||
this.S.config.awsAdminKeyId = this.S.getProvider('aws').getProfile(this.evt.options.profile).aws_access_key_id;
|
||||
this.S.config.awsAdminSecretKey = this.S.getProvider('aws').getProfile(this.evt.options.profile).aws_secret_access_key;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require( path.join( serverlessPath, 'ServerlessError' ) ),
|
||||
SError = require( path.join( serverlessPath, 'Error' ) ),
|
||||
SCli = require( path.join( serverlessPath, 'utils/cli' ) ),
|
||||
SUtils = require( path.join( serverlessPath, 'utils' ) ),
|
||||
BbPromise = require('bluebird'),
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
fs = require('fs'),
|
||||
BbPromise = require('bluebird'),
|
||||
@ -85,7 +85,7 @@ usage: serverless project remove`,
|
||||
*/
|
||||
|
||||
_removeAllStages() {
|
||||
§ let stages = this.S.getProject().getStages()
|
||||
let stages = this.S.getProject().getStages()
|
||||
|
||||
return BbPromise.each(stages, (stage) => {
|
||||
let evt = {
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
SUtils = require(path.join(serverlessPath, 'utils'));
|
||||
@ -142,16 +142,15 @@ usage: serverless region create`,
|
||||
return BbPromise.reject(new SError('Region "' + _this.evt.options.region + '" already exists in stage "' + _this.evt.options.stage + '"'));
|
||||
}
|
||||
|
||||
// Update and save Meta
|
||||
_this.meta = _this.S.state.getMeta();
|
||||
// Update and save Project
|
||||
const project = _this.S.getProject()
|
||||
const stage = project.getStage(_this.evt.options.stage);
|
||||
const region = new _this.S.classes.Region(_this.S, stage, _this.evt.options.region)
|
||||
|
||||
_this.meta.stages[_this.evt.options.stage].regions[_this.evt.options.region] = {
|
||||
variables: {
|
||||
region: _this.evt.options.region
|
||||
}
|
||||
};
|
||||
stage.addRegion(region);
|
||||
|
||||
return project.save();
|
||||
|
||||
return _this.meta.save();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,11 +172,11 @@ usage: serverless region create`,
|
||||
// Create bucket, or skip if already exists
|
||||
|
||||
const stage = this.evt.options.stage,
|
||||
region = this.evt.options.region,
|
||||
bucketName = this.S.state.getMeta().variables.projectBucket;
|
||||
bucketName = this.S.state.getMeta().variables.projectBucket,
|
||||
s3Region = bucketName.split('.')[1];
|
||||
|
||||
return this.S.getProvider('aws')
|
||||
.request('S3', 'getBucketAcl', { Bucket: bucketName }, stage, region)
|
||||
.request('S3', 'getBucketAcl', { Bucket: bucketName }, stage, s3Region)
|
||||
.then(() => SUtils.sDebug(`Project bucket already exists: ${bucketName}`))
|
||||
.catch(function(err) {
|
||||
|
||||
@ -193,7 +192,7 @@ usage: serverless region create`,
|
||||
SCli.log('Creating your project bucket on S3: ' + bucketName + '...');
|
||||
|
||||
return _this.S.getProvider('aws')
|
||||
.request('S3', 'createBucket', {Bucket: bucketName, ACL: 'private'}, stage, region);
|
||||
.request('S3', 'createBucket', {Bucket: bucketName, ACL: 'private'}, stage, s3Region);
|
||||
|
||||
} else {
|
||||
|
||||
@ -209,10 +208,11 @@ usage: serverless region create`,
|
||||
*/
|
||||
|
||||
_putEnvFile() {
|
||||
const projectName = this.S.getProject().name,
|
||||
stage = this.evt.options.stage,
|
||||
region = this.evt.options.region,
|
||||
key = ['serverless', projectName, stage, region, 'envVars', '.env'].join('/');
|
||||
const projectName = this.S.getProject().name,
|
||||
stage = this.evt.options.stage,
|
||||
region = this.evt.options.region,
|
||||
projectBucket = this.S.state.getMeta().variables.projectBucket,
|
||||
key = ['serverless', projectName, stage, region, 'envVars', '.env'].join('/');
|
||||
|
||||
// If noExeCf option, skip
|
||||
if (this.evt.options.noExeCf) return BbPromise.resolve();
|
||||
@ -222,16 +222,18 @@ usage: serverless region create`,
|
||||
SERVERLESS_DATA_MODEL_STAGE=${stage}
|
||||
SERVERLESS_PROJECT_NAME=${projectName}`;
|
||||
|
||||
let s3Region = projectBucket.split('.')[1];
|
||||
|
||||
let params = {
|
||||
Bucket: this.S.state.getMeta().variables.projectBucket,
|
||||
Key: key,
|
||||
Bucket: projectBucket,
|
||||
Key: "/" + key,
|
||||
ACL: 'private',
|
||||
ContentType: 'text/plain',
|
||||
Body: envFileContents
|
||||
};
|
||||
|
||||
return this.S.getProvider('aws')
|
||||
.request('S3', 'putObject', params, stage, region);
|
||||
.request('S3', 'putObject', params, stage, s3Region);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
fs = BbPromise.promisifyAll(require('fs')),
|
||||
@ -149,17 +149,19 @@ usage: serverless region remove`,
|
||||
_listS3Objects() {
|
||||
SUtils.sDebug("List related S3 objects");
|
||||
|
||||
let prefix = ['serverless', this.S.getProject().name, this.evt.options.stage, this.evt.options.region].join('/'),
|
||||
params = {
|
||||
let prefix = ['serverless', this.S.getProject().getName(), this.evt.options.stage, this.evt.options.region].join('/'),
|
||||
s3Region = this.S.state.getMeta().variables.projectBucket.split('.')[1],
|
||||
params = {
|
||||
Bucket: this.S.state.getMeta().variables.projectBucket,
|
||||
Prefix: prefix
|
||||
};
|
||||
return this.S.getProvider('aws').request('S3', 'listObjects', params, stage, region)
|
||||
.then(reply => {return _.map(reply.Contents, (item) => ({Key: item.Key}) )});
|
||||
return this.S.getProvider('aws').request('S3', 'listObjects', params, this.evt.options.stage, s3Region)
|
||||
.then(reply => _.map(reply.Contents, (item) => ({Key: item.Key})));
|
||||
}
|
||||
|
||||
_removeS3Objects(objects) {
|
||||
SUtils.sDebug("Removing related S3 objects");
|
||||
let s3Region = this.S.state.getMeta().variables.projectBucket.split('.')[1];
|
||||
|
||||
if (objects.length) {
|
||||
let params = {
|
||||
@ -168,7 +170,7 @@ usage: serverless region remove`,
|
||||
Objects: objects
|
||||
}
|
||||
};
|
||||
return this.S.getProvider('aws').request('S3', 'deleteObjects', params, stage, region);
|
||||
return this.S.getProvider('aws').request('S3', 'deleteObjects', params, this.evt.options.stage, s3Region);
|
||||
} else {
|
||||
SUtils.sDebug("S3 objects are not found. Skipping.");
|
||||
return BbPromise.resolve();
|
||||
@ -177,9 +179,8 @@ usage: serverless region remove`,
|
||||
|
||||
_removeMeta() {
|
||||
// Update and save Meta
|
||||
let meta = this.S.state.getMeta();
|
||||
delete meta.stages[this.evt.options.stage].regions[this.evt.options.region]
|
||||
return meta.save();
|
||||
this.S.getProject().getStage(this.evt.options.stage).removeRegion(this.evt.options.region);
|
||||
return this.S.getProject().save();
|
||||
}
|
||||
|
||||
_removeVariables() {
|
||||
|
||||
@ -9,7 +9,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
replaceall = require('replaceall'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
_ = require('lodash'),
|
||||
@ -156,7 +156,7 @@ usage: serverless resources deploy`,
|
||||
_deployResources() {
|
||||
|
||||
let _this = this;
|
||||
let regionVars = _this.S.state.getMeta().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables;
|
||||
let regionVars = _this.S.getProject().getRegion(_this.evt.options.stage, _this.evt.options.region)._variables
|
||||
let resourceVars = [ 'iamRoleArnLambda' ].concat( _this.S.getProject().resourceVars);
|
||||
|
||||
return _this.S.getProject().getResources({
|
||||
@ -262,7 +262,7 @@ usage: serverless resources deploy`,
|
||||
stage = this.evt.options.stage,
|
||||
region = this.evt.options.region,
|
||||
aws = this.S.getProvider('aws'),
|
||||
stackName = this.S.state.getMeta().stages[stage].regions[region].variables.resourcesStackName || aws.getLambdasStackName(stage, projectName);
|
||||
stackName = this.S.getProject().getRegion(stage, region)._variables.resourcesStackName || aws.getLambdasStackName(stage, projectName);
|
||||
|
||||
// CF Params
|
||||
let params = {
|
||||
@ -384,8 +384,10 @@ usage: serverless resources deploy`,
|
||||
Body: JSON.stringify(cfTemplate)
|
||||
};
|
||||
|
||||
let s3Region = bucketName.split('.')[1];
|
||||
|
||||
return this.S.getProvider('aws')
|
||||
.request('S3', 'putObject', params, stage, region)
|
||||
.request('S3', 'putObject', params, stage, s3Region)
|
||||
.then(function() {
|
||||
const hostname = new (require('aws-sdk').S3)().endpoint.hostname;
|
||||
return `https://${hostname}/${bucketName}/${key}`;
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
fs = BbPromise.promisifyAll(require('fs')),
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
BbPromise = require('bluebird'),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
@ -157,7 +157,7 @@ usage: serverless resources remove`,
|
||||
let _this = this,
|
||||
stage = _this.evt.options.stage,
|
||||
region = _this.evt.options.region,
|
||||
regionVars = _this.S.state.getMeta().stages[stage].regions[region].variables,
|
||||
regionVars = _this.S.getProject().getRegion(stage, region)._variables,
|
||||
projectBucket = _this.S.state.getMeta().variables.projectBucket,
|
||||
projectName = _this.S.getProject().getName(),
|
||||
aws = _this.S.getProvider('aws');
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
os = require('os'),
|
||||
fs = require('fs'),
|
||||
@ -182,21 +182,25 @@ usage: serverless stage create`,
|
||||
*/
|
||||
|
||||
_createStage() {
|
||||
const project = this.S.getProject();
|
||||
const stage = new this.S.classes.Stage(this.S, project, this.evt.options.stage);
|
||||
|
||||
let _this = this;
|
||||
project.addStage(stage);
|
||||
|
||||
// Update Meta
|
||||
_this.meta = _this.S.state.getMeta();
|
||||
return project.save();
|
||||
|
||||
_this.meta.stages[_this.evt.options.stage] = {
|
||||
regions: {},
|
||||
variables: {
|
||||
stage: _this.evt.options.stage
|
||||
}
|
||||
};
|
||||
// // Update Meta
|
||||
// _this.meta = _this.S.state.getMeta();
|
||||
|
||||
// _this.meta.stages[_this.evt.options.stage] = {
|
||||
// regions: {},
|
||||
// variables: {
|
||||
// stage: _this.evt.options.stage
|
||||
// }
|
||||
// };
|
||||
|
||||
// Save Meta before adding region
|
||||
return _this.meta.save();
|
||||
// return _this.meta.save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SError = require(path.join(serverlessPath, 'Error')),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
fs = require('fs'),
|
||||
BbPromise = require('bluebird'),
|
||||
@ -128,12 +128,11 @@ usage: serverless stage remove`,
|
||||
|
||||
_removeMeta() {
|
||||
// Update Meta
|
||||
this.meta = this.S.state.getMeta();
|
||||
|
||||
delete this.meta.stages[this.evt.options.stage]
|
||||
let project = this.S.getProject();
|
||||
project.removeStage(this.evt.options.stage);
|
||||
|
||||
// Save Meta before adding region
|
||||
return this.meta.save();
|
||||
return project.save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -387,14 +387,16 @@ exports.doesFunctionExist = function(functionName, componentName, projectRootPat
|
||||
|
||||
exports.populate = function(meta, templates, data, stage, region) {
|
||||
|
||||
const project = meta._S.getProject()
|
||||
|
||||
// Validate required params
|
||||
if (!meta || !templates || !data || !stage || !region) throw new SError(`Missing required params: Serverless, project, stage, region`);
|
||||
|
||||
// Validate: Check stage exists
|
||||
if (typeof stage != 'undefined' && !meta.stages[stage]) throw new SError(`Stage doesn't exist`);
|
||||
if (typeof stage != 'undefined' && !project.validateStageExists(stage)) throw new SError(`Stage doesn't exist`);
|
||||
|
||||
// Validate: Check region exists in stage
|
||||
if (typeof region != 'undefined' && !meta.stages[stage].regions[region]) throw new SError(`Region doesn't exist in provided stage`);
|
||||
if (typeof region != 'undefined' && !project.validateRegionExists(stage, region)) throw new SError(`Region doesn't exist in provided stage`);
|
||||
|
||||
// Sanitize: Remove nested properties. DO NOT populate these. Rely on calling those classes toObjectPopulated methods instead.
|
||||
if (data.components) delete data.components;
|
||||
@ -403,12 +405,12 @@ exports.populate = function(meta, templates, data, stage, region) {
|
||||
let varTemplateSyntax = /\${([\s\S]+?)}/g,
|
||||
templateTemplateSyntax = /\$\${([\s\S]+?)}/g;
|
||||
|
||||
if (meta._S.getProject().variableSyntax) {
|
||||
varTemplateSyntax = RegExp(meta._S.getProject().variableSyntax,'g');
|
||||
if (project.variableSyntax) {
|
||||
varTemplateSyntax = RegExp(project.variableSyntax,'g');
|
||||
}
|
||||
|
||||
if (meta._S.getProject().templateSyntax) {
|
||||
templateTemplateSyntax = RegExp(meta._S.getProject().templateSyntax,'g');
|
||||
if (project.templateSyntax) {
|
||||
templateTemplateSyntax = RegExp(project.templateSyntax,'g');
|
||||
}
|
||||
|
||||
// Populate templates
|
||||
@ -449,10 +451,10 @@ exports.populate = function(meta, templates, data, stage, region) {
|
||||
let variableName = variableSyntax.replace(varTemplateSyntax, (match, varName) => varName.trim());
|
||||
let value;
|
||||
|
||||
if (meta.stages[stage].regions[region].variables[variableName]) {
|
||||
value = meta.stages[stage].regions[region].variables[variableName]
|
||||
} else if (meta.stages[stage].variables[variableName]) {
|
||||
value = meta.stages[stage].variables[variableName];
|
||||
if (project.getRegion(stage, region)._variables[variableName]) {
|
||||
value = project.getRegion(stage, region)._variables[variableName]
|
||||
} else if (project.getStage(stage)._variables[variableName]) {
|
||||
value = project.getStage(stage)._variables[variableName];
|
||||
} else if (meta.variables[variableName]) {
|
||||
value = meta.variables[variableName];
|
||||
}
|
||||
@ -550,6 +552,7 @@ function getStack() {
|
||||
*/
|
||||
|
||||
exports.persistentRequest = function(f) {
|
||||
let _this = this;
|
||||
|
||||
return new BbPromise(function(resolve, reject){
|
||||
let doCall = function(){
|
||||
@ -558,7 +561,7 @@ exports.persistentRequest = function(f) {
|
||||
.catch(function(error) {
|
||||
|
||||
if( error.statusCode == 429 ) {
|
||||
SUtils.sDebug("'Too many requests' received, sleeping 5 seconds");
|
||||
_this.sDebug("'Too many requests' received, sleeping 5 seconds");
|
||||
setTimeout( doCall, 5000 );
|
||||
} else
|
||||
reject( error );
|
||||
@ -614,7 +617,9 @@ exports.getEnvFileAsMap = function(Serverless, region, stage) {
|
||||
deferred = Promise.resolve(fs.readFileSync(Serverless.project.getFilePath( '.env' )));
|
||||
} else {
|
||||
let projectName = Serverless.state.meta.get().variables.project,
|
||||
bucketName = Serverless.state.meta.get().variables.projectBucket;
|
||||
bucketName = Serverless.state.meta.get().variables.projectBucket,
|
||||
s3Region = bucketName.split('.')[1];
|
||||
|
||||
|
||||
SCli.log(`Getting ENV file from S3 bucket: ${bucketName}`);
|
||||
|
||||
@ -625,7 +630,9 @@ exports.getEnvFileAsMap = function(Serverless, region, stage) {
|
||||
Bucket: bucketName,
|
||||
Key: key
|
||||
};
|
||||
deferred = aws.request('S3', 'getObject', params, stage, region)
|
||||
|
||||
|
||||
deferred = aws.request('S3', 'getObject', params, stage, s3Region)
|
||||
.then(function(s3ObjData) {
|
||||
return (!s3ObjData.Body) ? '' : s3ObjData.Body;
|
||||
});
|
||||
|
||||
48
tests/all.js
48
tests/all.js
@ -10,29 +10,29 @@ describe('All Tests', function() {
|
||||
});
|
||||
|
||||
after(function() {});
|
||||
require('./tests/classes/ServerlessStateTest');
|
||||
require('./tests/classes/ServerlessProjectTest');
|
||||
require('./tests/classes/ServerlessComponentTest');
|
||||
require('./tests/classes/ServerlessFunctionTest');
|
||||
require('./tests/classes/ServerlessEndpointTest');
|
||||
require('./tests/actions/TestPluginCustom');
|
||||
require('./tests/actions/TestDefaultActionHook');
|
||||
require('./tests/actions/StageCreate');
|
||||
require('./tests/actions/RegionCreate');
|
||||
require('./tests/actions/ComponentCreate');
|
||||
require('./tests/actions/FunctionCreate');
|
||||
require('./tests/actions/EnvList');
|
||||
require('./tests/actions/EnvGet');
|
||||
require('./tests/actions/EnvSetUnset');
|
||||
require('./tests/actions/ResourcesDeploy');
|
||||
require('./tests/actions/FunctionRun');
|
||||
require('./tests/actions/FunctionLogs');
|
||||
require('./tests/actions/FunctionDeploy');
|
||||
require('./tests/actions/EndpointDeploy');
|
||||
//require('./tests/classes/ServerlessStateTest');
|
||||
//require('./tests/classes/ServerlessProjectTest');
|
||||
//require('./tests/classes/ServerlessComponentTest');
|
||||
//require('./tests/classes/ServerlessFunctionTest');
|
||||
//require('./tests/classes/ServerlessEndpointTest');
|
||||
//require('./tests/actions/TestPluginCustom');
|
||||
//require('./tests/actions/TestDefaultActionHook');
|
||||
//require('./tests/actions/StageCreate');
|
||||
//require('./tests/actions/RegionCreate');
|
||||
//require('./tests/actions/ComponentCreate');
|
||||
//require('./tests/actions/FunctionCreate');
|
||||
//require('./tests/actions/EnvList');
|
||||
//require('./tests/actions/EnvGet');
|
||||
//require('./tests/actions/EnvSetUnset');
|
||||
//require('./tests/actions/ResourcesDeploy');
|
||||
//require('./tests/actions/FunctionRun');
|
||||
//require('./tests/actions/FunctionLogs');
|
||||
//require('./tests/actions/FunctionDeploy');
|
||||
//require('./tests/actions/EndpointDeploy');
|
||||
require('./tests/actions/EventDeploy');
|
||||
require('./tests/actions/ProjectInit');
|
||||
require('./tests/actions/ProjectInstall');
|
||||
require('./tests/actions/ProjectLifeCycle.js');
|
||||
require('./tests/actions/ResourcesDiff');
|
||||
require('./tests/actions/PluginCreate');
|
||||
//require('./tests/actions/ProjectInit');
|
||||
//require('./tests/actions/ProjectInstall');
|
||||
//require('./tests/actions/ProjectLifeCycle.js');
|
||||
//require('./tests/actions/ResourcesDiff');
|
||||
//require('./tests/actions/PluginCreate');
|
||||
});
|
||||
@ -88,7 +88,7 @@ let cleanup = function(Meta, cb, evt) {
|
||||
// Delete CloudFormation Resources Stack
|
||||
let cloudformation = new AWS.CloudFormation();
|
||||
cloudformation.deleteStack({
|
||||
StackName: Meta.stages[config.stage].regions[config.region].variables.resourcesStackName
|
||||
StackName: serverless.getProject().getRegion(config.stage, config.region)._variables.resourcesStackName
|
||||
}, function (err, data) {
|
||||
if (err) console.log(err, err.stack); // an error occurred
|
||||
|
||||
@ -140,14 +140,17 @@ describe('Test action: Project Init', function() {
|
||||
|
||||
// Validate Meta
|
||||
let Meta = serverless.state.getMeta();
|
||||
let stage = serverless.getProject().getStage(config.stage);
|
||||
let region = serverless.getProject().getRegion(config.stage, config.region);
|
||||
|
||||
assert.equal(true, typeof Meta.variables.project != 'undefined');
|
||||
assert.equal(true, typeof Meta.variables.domain != 'undefined');
|
||||
assert.equal(true, typeof Meta.variables.projectBucket != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].variables.stage != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.region != 'undefined');
|
||||
assert.equal(true, typeof stage._variables.stage != 'undefined');
|
||||
assert.equal(true, typeof region._variables.region != 'undefined');
|
||||
if (!config.noExecuteCf) {
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.iamRoleArnLambda != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.resourcesStackName != 'undefined');
|
||||
assert.equal(true, typeof region._variables.iamRoleArnLambda != 'undefined');
|
||||
assert.equal(true, typeof region._variables.resourcesStackName != 'undefined');
|
||||
}
|
||||
|
||||
// Validate Event
|
||||
|
||||
@ -140,15 +140,18 @@ describe('Test action: Project Install', function() {
|
||||
|
||||
// Validate Meta
|
||||
let Meta = serverless.state.getMeta();
|
||||
let stage = serverless.getProject().getStage(config.stage);
|
||||
let region = serverless.getProject().getRegion(config.stage, config.region);
|
||||
|
||||
|
||||
assert.equal(true, typeof Meta.variables.project != 'undefined');
|
||||
assert.equal(true, typeof Meta.variables.domain != 'undefined');
|
||||
assert.equal(true, typeof Meta.variables.projectBucket != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].variables.stage != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.region != 'undefined');
|
||||
assert.equal(true, typeof stage._variables.stage != 'undefined');
|
||||
assert.equal(true, typeof region._variables.region != 'undefined');
|
||||
if (!config.noExecuteCf) {
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.iamRoleArnLambda != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.resourcesStackName != 'undefined');
|
||||
assert.equal(true, typeof region._variables.iamRoleArnLambda != 'undefined');
|
||||
assert.equal(true, typeof region._variables.resourcesStackName != 'undefined');
|
||||
}
|
||||
|
||||
// Validate Event
|
||||
|
||||
@ -105,7 +105,8 @@ describe('Test Action: Region Create', function() {
|
||||
|
||||
let Meta = serverless.state.meta;
|
||||
//console.log(serverless.state.meta.stages)
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region2].variables.region != 'undefined');
|
||||
|
||||
assert.equal(true, typeof serverless.getProject().getRegion(config.stage, config.region2)._variables.region != 'undefined');
|
||||
|
||||
// Validate Event
|
||||
validateEvent(evt);
|
||||
|
||||
@ -97,8 +97,9 @@ describe('Test Action: Stage Create', function() {
|
||||
.then(function(evt) {
|
||||
|
||||
let Meta = serverless.state.meta;
|
||||
assert.equal(true, typeof Meta.stages[config.stage2].variables.stage != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage2].regions[config.region].variables.region != 'undefined');
|
||||
let project = serverless.getProject();
|
||||
assert.equal(true, typeof project.getStage(config.stage2)._variables.stage != 'undefined');
|
||||
assert.equal(true, typeof project.getRegion(config.stage2, config.region)._variables.region != 'undefined');
|
||||
|
||||
// Validate EVT
|
||||
validateEvent(evt);
|
||||
|
||||
@ -116,14 +116,18 @@ describe('Test: Project Live Cycle', function() {
|
||||
|
||||
// Validate Meta
|
||||
let Meta = serverless.state.getMeta();
|
||||
let stage = serverless.getProject().getStage(config.stage);
|
||||
let region = serverless.getProject().getRegion(config.stage, config.region);
|
||||
|
||||
|
||||
assert.equal(true, typeof Meta.variables.project != 'undefined');
|
||||
assert.equal(true, typeof Meta.variables.domain != 'undefined');
|
||||
assert.equal(true, typeof Meta.variables.projectBucket != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].variables.stage != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.region != 'undefined');
|
||||
assert.equal(true, typeof stage._variables.stage != 'undefined');
|
||||
assert.equal(true, typeof region._variables.region != 'undefined');
|
||||
if (!config.noExecuteCf) {
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.iamRoleArnLambda != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.resourcesStackName != 'undefined');
|
||||
assert.equal(true, typeof region._variables.iamRoleArnLambda != 'undefined');
|
||||
assert.equal(true, typeof region._variables.resourcesStackName != 'undefined');
|
||||
}
|
||||
|
||||
// Validate Event
|
||||
@ -156,8 +160,11 @@ describe('Test: Project Live Cycle', function() {
|
||||
.then(function(evt) {
|
||||
|
||||
let Meta = serverless.state.meta;
|
||||
assert.equal(true, typeof Meta.stages[config.stage2].variables.stage != 'undefined');
|
||||
assert.equal(true, typeof Meta.stages[config.stage2].regions[config.region].variables.region != 'undefined');
|
||||
let stage = serverless.getProject().getStage(config.stage2);
|
||||
let region = serverless.getProject().getRegion(config.stage2, config.region);
|
||||
|
||||
assert.equal(true, typeof stage._variables.stage != 'undefined');
|
||||
assert.equal(true, typeof region._variables.region != 'undefined');
|
||||
|
||||
// Validate EVT
|
||||
validateEvent(evt);
|
||||
@ -188,8 +195,7 @@ describe('Test: Project Live Cycle', function() {
|
||||
|
||||
return serverless.actions.regionCreate(evt)
|
||||
.then(function(evt) {
|
||||
let Meta = serverless.state.meta;
|
||||
assert.equal(true, typeof Meta.stages[config.stage2].regions[config.region2].variables.region != 'undefined');
|
||||
assert.equal(true, typeof serverless.getProject().getRegion(config.stage2, config.region2)._variables.region != 'undefined');
|
||||
|
||||
// Validate Event
|
||||
validateEvent(evt);
|
||||
|
||||
@ -31,7 +31,6 @@ describe('Test Serverless Project Class', function() {
|
||||
|
||||
return serverless.init()
|
||||
.then(function() {
|
||||
|
||||
// Instantiate Class
|
||||
instance = serverless.getProject();
|
||||
|
||||
@ -78,7 +77,7 @@ describe('Test Serverless Project Class', function() {
|
||||
// These functions have their own s-templates.json files which give them the same template, with one different property
|
||||
|
||||
// Function1 template
|
||||
assert.equal(true, data.components.nodejscomponent.functions['nodejscomponent/group1/function1'].endpoints[0].requestTemplates['application/json'].pathParams === "$input.path('$.id1')");
|
||||
assert.equal(data.components.nodejscomponent.functions['nodejscomponent/group1/function1'].endpoints[0].requestTemplates['application/json'].pathParams, "$input.path('$.id1')");
|
||||
// Function2 template
|
||||
assert.equal(true, data.components.nodejscomponent.functions['nodejscomponent/group1/function2'].endpoints[0].requestTemplates['application/json'].pathParams === "$input.path('$.id2')");
|
||||
// Function3 template - s-templates.json left undefined
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user