Last active
September 16, 2019 18:52
-
-
Save DV8FromTheWorld/38a3b9da80392f71d31513e957168b28 to your computer and use it in GitHub Desktop.
Open Cloudwatch Insights
This file contains hidden or 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
;(() => { | |
const url = "https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs-insights:queryDetail=~(end~0~start~-900~timeType~'RELATIVE~unit~'seconds~editorString~'fields*20*20*40timestamp*2c*20*40message*0a*20*7c*20limit*2020~isLiveTail~false~queryId~'CW_LOG_NAME~source~'CW_LOG_NAME)"; | |
const regionFromUrl = /.*\?region=(.+?)#.*/; | |
const logGroupFromCloudwatch = /.*group=([^;]*?)(;|$)/; | |
const logGroupFromLambda = /.*functions\/([^?]*)/; | |
const logGroupToken = /CW_LOG_NAME/g; | |
let logGroup = null; | |
const regionResult = regionFromUrl.exec(window.location.href); | |
const cloudwatchResult = logGroupFromCloudwatch.exec(window.location.href); | |
const lambdaResult = logGroupFromLambda.exec(window.location.href); | |
if (cloudwatchResult) { | |
logGroup = cloudwatchResult[1]; | |
} | |
else if (lambdaResult) { | |
let lambdaLogName = lambdaResult[1]; | |
if (!confirm("Click 'OK' if this is a normal lambda. If this is a Lambda@Edge, click 'Cancel'")) { | |
lambdaLogName = `${regionResult[1]}.${lambdaResult[1]}`; | |
} | |
logGroup = `/aws/lambda/${lambdaLogName}`; | |
} | |
if (!logGroup) { | |
alert("Could not find log group information on this page. Are you on a Lambda or Cloudwatch group/stream page?"); | |
return; | |
} | |
window.open(url.replace(logGroupToken, logGroup), "_blank"); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment