AWS CloudWatch Log Insights Generate URL

0

Is it possible to deterministically generate a URL for CloudWatch Log Insights given the log group, start time, and query (text area that allows fields, sorts, filters, etc...)? The URL is extremely long and does not have standard URL encoding from what I can tell.

There are plenty of suggestions in the below Stack Overflow post about the topic but I was curious if there was a more official guide to doing this?

https://stackoverflow.com/questions/60796991/is-there-a-way-to-generate-the-aws-console-urls-for-cloudwatch-log-group-filters

1回答
3
承認された回答

In addition to the suggestions in the Stack Overflow post, here is some further info on how the Logs Insights URLs are generated that may help you.

The deep link of Logs Insights query is generated in three steps:

Step 1. Define the queryDetails in a JSON structure

 {
        editorString: '',
        end: '',
        queryId: '',
        source: '',
        start: '',
        timeType: '',
        tz: '',
        unit: ''
    };

Step 2. It uses jsurl (https://www.npmjs.com/package/jsurl) to encode the JSON object logs-insights?queryDetail=<encoded js url>

Step 3. It uses following map to replace the special characters inside logs-insights?queryDetail=<encoded js url>

 {
  '!' = '$21',
  '#' = '$23',
  '%' = '$25',
  '&' = '$26',

  // Spaces are encoded as +. That's what GWT uses when we do not manually
  //   encode our routes, so it is backwards compatible with customer links
  //   generated prior to this manual encoding process.
  ' ' = '$2B',
  ':' = '$3A',
  ';' = '$3B',
  '=' = '$3D',
  '?' = '$3F',
}

Step 4. add prefix https://console.aws.amazon.com/cloudwatch/home?region=<region>#logsV2:

To get more details, you can use some example URL and reverse the steps and see what the original JSON structure looks like.

AWS
サポートエンジニア
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ