mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
adds auto discovering new function versions to FunctionLogs action when tailing
This commit is contained in:
parent
d4bf6c9ad2
commit
ec40e36e65
@ -143,19 +143,16 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
const lambdaName = this.Lambda.sGetLambdaName(func.getProject().name, func.getComponent().name, func.getModule().name, func.name);
|
||||
|
||||
this.evt.data.logGroupName = '/aws/lambda/' + lambdaName;
|
||||
|
||||
// get functon version
|
||||
let params = {
|
||||
FunctionName: lambdaName,
|
||||
Name: this.evt.options.stage
|
||||
};
|
||||
|
||||
return this.Lambda.getAliasPromised(params)
|
||||
.then(reply => this.evt.data.version = reply.FunctionVersion);
|
||||
this.evt.data.lambdaName = lambdaName;
|
||||
}
|
||||
|
||||
_getLogStreamNames() {
|
||||
return this.CWL.sGetLogStreams(this.evt.data.logGroupName, 50)
|
||||
return this.Lambda.getAliasPromised({
|
||||
FunctionName: this.evt.data.lambdaName,
|
||||
Name: this.evt.options.stage
|
||||
})
|
||||
.then(reply => this.evt.data.version = reply.FunctionVersion)
|
||||
.then(() => this.CWL.sGetLogStreams(this.evt.data.logGroupName, 50))
|
||||
.then(reply => reply.logStreams)
|
||||
.then( logStreams => {
|
||||
if (logStreams.length === 0) return BbPromise.reject(new SError('No existing streams for the function'));
|
||||
@ -188,6 +185,14 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
return this._getLogStreamNames()
|
||||
.then( logStreamNames => {
|
||||
|
||||
if (!logStreamNames.length) {
|
||||
if (this.evt.options.tail) {
|
||||
return setTimeout((()=> this._showLogs()), this.evt.options.pollInterval);
|
||||
} else {
|
||||
return BbPromise.reject(new SError('No existing streams for the function'));
|
||||
}
|
||||
}
|
||||
|
||||
let params = {
|
||||
logGroupName: this.evt.data.logGroupName,
|
||||
interleaved: true,
|
||||
@ -198,33 +203,33 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
if (this.evt.options.filter) params.filterPattern = this.evt.options.filter;
|
||||
if (this.evt.data.nextToken) params.nextToken = this.evt.data.nextToken;
|
||||
|
||||
return this.CWL.filterLogEventsAsync(params);
|
||||
})
|
||||
.then(results => {
|
||||
return this.CWL.filterLogEventsAsync(params)
|
||||
.then(results => {
|
||||
|
||||
if (this.S.config.interactive) {
|
||||
results.events.forEach(e => {
|
||||
process.stdout.write(this._formatLogEvent(e));
|
||||
if (this.S.config.interactive && results.events) {
|
||||
results.events.forEach(e => {
|
||||
process.stdout.write(this._formatLogEvent(e));
|
||||
});
|
||||
}
|
||||
|
||||
if (results.nextToken) {
|
||||
this.evt.data.nextToken = results.nextToken;
|
||||
} else {
|
||||
delete this.evt.data.nextToken;
|
||||
}
|
||||
|
||||
if (this.evt.options.tail) {
|
||||
if (results.events && results.events.length) {
|
||||
this.evt.data.startTime = _.last(results.events).timestamp + 1;
|
||||
}
|
||||
|
||||
return setTimeout((()=> this._showLogs()), this.evt.options.pollInterval);
|
||||
}
|
||||
else {
|
||||
return this.evt.data.results = results.events;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (results.nextToken) {
|
||||
this.evt.data.nextToken = results.nextToken;
|
||||
} else {
|
||||
delete this.evt.data.nextToken;
|
||||
}
|
||||
|
||||
if (this.evt.options.tail) {
|
||||
if (results.events.length) {
|
||||
this.evt.data.startTime = _.last(results.events).timestamp + 1;
|
||||
}
|
||||
|
||||
return setTimeout((()=> this._showLogs()), this.evt.options.pollInterval);
|
||||
}
|
||||
else {
|
||||
return this.evt.data.results = results.events;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user