Created
March 27, 2021 12:02
-
-
Save mpuhacz/b7e0e957c427cf43484cd23f51dd1f02 to your computer and use it in GitHub Desktop.
Generates AWS Cloudwatch insights console URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getInsightsUrl( | |
start: Date, | |
end: Date, | |
query: string, | |
sourceGroup: string, | |
region = "us-east-1" | |
) { | |
const p = (m: string) => escape(m); | |
// encodes inner values | |
const s = (m: string) => escape(m).replace(/\%/gi, "*"); | |
const queryDetail = | |
p(`~(end~'`) + | |
s(end.toISOString()) + | |
p(`~start~'`) + | |
s(start.toISOString()) + | |
p(`~timeType~'ABSOLUTE~tz~'UTC~editorString~'`) + | |
s(query) + | |
p(`~isLiveTail~false~queryId~'`) + | |
s(v4()) + | |
p(`~source~(~'`) + | |
s(sourceGroup) + | |
p(`))`); | |
return ( | |
`https://console.aws.amazon.com/cloudwatch/home?region=${region}#logsV2:logs-insights` + | |
escape("?queryDetail=" + queryDetail).replace(/\%/gi, "$") | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment