mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
commit
4b08161cee
@ -50,6 +50,10 @@ class ServerlessStage extends VarContainer {
|
||||
this._regions[ region.getName() ] = region;
|
||||
}
|
||||
|
||||
destroy(){
|
||||
|
||||
}
|
||||
|
||||
removeRegion( name ){
|
||||
let region = this._regions[ name ];
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
});
|
||||
|
||||
@ -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
|
||||
@ -182,7 +183,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
// Get ENV file from S3
|
||||
let NoSuchKey = {code: 'NoSuchKey'};
|
||||
return _this.aws.request('S3', 'getObject', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
return _this.aws.request('S3', 'getObject', params, _this.evt.options.stage, s3Region)
|
||||
.catch(NoSuchKey => ({Body: ''}))
|
||||
.then(function(s3ObjData) {
|
||||
|
||||
|
||||
@ -83,6 +83,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
return _this.aws.request('Lambda', 'addPermission', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
})
|
||||
.then(function(data) {
|
||||
let s3Region = _this.S.state.getMeta().variables.projectBucket.split('.')[1];
|
||||
let params = {
|
||||
Bucket: populatedEvent.config.bucket,
|
||||
NotificationConfiguration: {
|
||||
@ -94,7 +95,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
]
|
||||
}
|
||||
};
|
||||
return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, s3Region);
|
||||
})
|
||||
.then(function(data) {
|
||||
|
||||
|
||||
@ -173,11 +173,10 @@ usage: serverless region create`,
|
||||
|
||||
const stage = this.evt.options.stage,
|
||||
bucketName = this.S.state.getMeta().variables.projectBucket,
|
||||
region = this.evt.options.region;
|
||||
// region = bucketName.split('.')[1];
|
||||
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,8 +222,10 @@ 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,
|
||||
Bucket: projectBucket,
|
||||
Key: "/" + key,
|
||||
ACL: 'private',
|
||||
ContentType: 'text/plain',
|
||||
@ -231,7 +233,7 @@ SERVERLESS_PROJECT_NAME=${projectName}`;
|
||||
};
|
||||
|
||||
return this.S.getProvider('aws')
|
||||
.request('S3', 'putObject', params, stage, region);
|
||||
.request('S3', 'putObject', params, stage, s3Region);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -149,17 +149,19 @@ usage: serverless region remove`,
|
||||
_listS3Objects() {
|
||||
SUtils.sDebug("List related S3 objects");
|
||||
|
||||
let prefix = ['serverless', this.S.getProject().getName(), 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, this.evt.options.stage, this.evt.options.region)
|
||||
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, this.evt.options.stage, this.evt.options.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();
|
||||
|
||||
@ -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}`;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -529,7 +529,8 @@ 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}`);
|
||||
|
||||
@ -540,7 +541,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;
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user