cwl-link
creates a link for CloudWatch Logs.
cwl-link
is available as an npm package.
// with npm
npm install cwl-link
// with yarn
yarn add cwl-link
// ES5 example
const cwllink = require('cwl-link');
// ES6+ example
import * as cwllink from 'cwl-link';
exports.handler = function(event, context) {
// This is a link for a Log Event page filtered by request id.
const link = cwllink.fromLambdaContext(context);
}
exports.handler = async function(event, context) {
const link = await cwllink.fromLambdaEventTriggeredBySubscriptionFilters(event);
}
Or you can use decoded data.
exports.handler = async function(event, context) {
const decoded = await cwllink.decodeCloudWatchLogsData(event.awslogs.data);
// you can use decoded data.
const link = cwllink.fromCloudWatchLogsData(decoded);
}
const region = '...';
const logGroupName = '...';
const logGroupLink = cwllink.create(region, logGroupName);
const logEventName = '...';
const logEventLink = cwllink.create(region, logGroupName, logEventName);
const terms = ['...'];
const filteredByTermsLink = cwllink.create(region, logGroupName, logEventName, { terms });
const start = 1_649_602_800_000; // unix time(ms): 2022-04-12 00:00:00
const filteredByStartLink = cwllink.create(region, logGroupName, logEventName, { start });
const start = -3_600_000; // in the last hour(ms):
const filteredByRelativeStartLink = cwllink.create(region, logGroupName, logEventName, { start });
const end = 1_649_689_199_000; // unix time(ms): 2022-04-12 23:59:59
const filteredByEndLink = cwllink.create(region, logGroupName, logEventName, { end });
const filteredByMixLink = cwllink.create(region, logGroupName, logEventName, { terms, start, end });
These Usages have been tested.
Ƭ FilterOptions: Object
Options for filtering logs.
Name | Type | Description |
---|---|---|
end? |
number |
You can provide unix timestamp. |
start? |
number |
You can provide the absolute or relative time(ms). - if you provide unix timestamp, it is treated as absolute time. - if you provide negative number, it is treated as relative time. |
terms? |
string [] |
You can filter by string array. |
▸ create(region
, logGroup
, logEvents?
, options?
): string
Create a link for CloudWatch Logs.
Name | Type | Description |
---|---|---|
region |
string |
|
logGroup |
string |
|
logEvents? |
string |
optional parameter |
options? |
FilterOptions |
optional parameter for filtering logs |
string
a link for CloudWatch Logs.
▸ decodeCloudWatchLogsData(data
): Promise
<CloudWatchLogsDecodedData
>
Decode CloudWatch Logs data.
Name | Type | Description |
---|---|---|
data |
string |
base64 of zipped data. |
Promise
<CloudWatchLogsDecodedData
>
CloudWatch Logs decoded data.
▸ fromCloudWatchLogsData(data
): string
Create a link for CloudWatch Logs from CloudWatchLogsDecodedData.
Name | Type | Description |
---|---|---|
data |
CloudWatchLogsDecodedData |
CloudWatch Logs decoded data. |
string
a link for a Log Event page filtered by request id.
▸ fromLambdaContext(context
): string
Create a link for CloudWatch Logs from a context of AWS Lambda.
Name | Type | Description |
---|---|---|
context |
Context |
a context of AWS Lambda. |
string
a link for a Log Event page filtered by request id.
▸ fromLambdaEventTriggeredBySubscriptionFilters(event
): Promise
<string
>
Create a link for CloudWatch Logs from a event of AWS Lambda triggered by Subscription Filters.
Name | Type | Description |
---|---|---|
event |
CloudWatchLogsEvent |
a event of AWS Lambda triggered by Subscription Filters. |
Promise
<string
>
a link for a Log Event page filtered by request id.
▸ gunzipAsync(src
): Promise
<Buffer
>
gunzipAsync is a promise wrapper of zlib.gunzip.
Name | Type |
---|---|
src |
Buffer |
Promise
<Buffer
>
decompressed