-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcloudwatch-helpers.ts
More file actions
36 lines (30 loc) · 956 Bytes
/
cloudwatch-helpers.ts
File metadata and controls
36 lines (30 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
CloudWatchLogsClient,
FilterLogEventsCommand,
} from '@aws-sdk/client-cloudwatch-logs';
import { region } from 'utils';
import { test } from '@playwright/test';
const client = new CloudWatchLogsClient({ region: region() });
let testStartTime = new Date();
test.beforeEach(() => {
testStartTime = new Date();
});
/**
* @param logGroupName e.g. '/aws/lambda/nhs-main-dl-apim-key-generation'
* @param patterns e.g. [ '$.id = "someId"', '$.message.messageUri = "messageUri"' ]
*/
export async function getLogsFromCloudwatch(
logGroupName: string,
patterns: string[],
): Promise<unknown[]> {
const filterEvents = new FilterLogEventsCommand({
logGroupName,
startTime: testStartTime.getTime() - 60 * 1000,
filterPattern: `{${patterns.join(' && ')}}`,
limit: 50,
});
const { events = [] } = await client.send(filterEvents);
return events.flatMap(({ message }) =>
message ? [JSON.parse(message)] : [],
);
}