File tree Expand file tree Collapse file tree 2 files changed +7
-0
lines changed Expand file tree Collapse file tree 2 files changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ jest.mock('aws-sdk', () => {
15
15
return { CloudWatchLogs } ;
16
16
} ) ;
17
17
18
+ jest . spyOn ( Date , 'now' ) . mockImplementation ( ( ) => 12 * 60 * 60 * 1000 ) ;
19
+
18
20
describe ( 'cloudwatch utils' , ( ) => {
19
21
const AWS = require ( 'aws-sdk' ) ;
20
22
const cloudWatchLogs = AWS . CloudWatchLogs ;
@@ -91,6 +93,7 @@ describe('cloudwatch utils', () => {
91
93
interleaved : true ,
92
94
limit : 1 ,
93
95
logGroupName,
96
+ startTime : 11 * 60 * 60 * 1000 ,
94
97
} ) ;
95
98
expect ( actual ) . toEqual ( { events } ) ;
96
99
} ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import AWS = require('aws-sdk');
2
2
3
3
const getLogGroupName = ( functionName : string ) => `/aws/lambda/${ functionName } ` ;
4
4
5
+ const hoursToMilliseconds = ( hours : number ) => hours * 60 * 60 * 1000 ;
6
+
5
7
export const filterLogEvents = async (
6
8
region : string ,
7
9
functionName : string ,
@@ -10,13 +12,15 @@ export const filterLogEvents = async (
10
12
const cloudWatchLogs = new AWS . CloudWatchLogs ( { region } ) ;
11
13
const logGroupName = getLogGroupName ( functionName ) ;
12
14
const filterPattern = `"${ pattern } "` ; // enclose with "" to support special characters
15
+ const startTime = Date . now ( ) - hoursToMilliseconds ( 1 ) ;
13
16
14
17
const { events = [ ] } = await cloudWatchLogs
15
18
. filterLogEvents ( {
16
19
filterPattern,
17
20
interleaved : true ,
18
21
limit : 1 ,
19
22
logGroupName,
23
+ startTime,
20
24
} )
21
25
. promise ( ) ;
22
26
You can’t perform that action at this time.
0 commit comments