Created
March 27, 2020 20:50
-
-
Save jelder/df8c673a4ea2e5a8d2710bc54cef8076 to your computer and use it in GitHub Desktop.
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
import { URL } from "url" | |
/** Construct a deep link to the CloudWatch Logs console given a Lambda execution context and start time */ | |
const cloudwatchUrl = context => { | |
const path = "cloudwatch/home" | |
const url = new URL(path, "https://console.aws.amazon.com/") | |
let region | |
if (typeof context.invokedFunctionArn === "string") { | |
const [, , , arnRegion, accountId, , functionName] = context.invokedFunctionArn.split(":") | |
region = arnRegion | |
} else { | |
region = "us-east-1" | |
} | |
url.searchParams.set("region", region) | |
url.hash = | |
"logEventViewer:" + | |
querystring.stringify( | |
{ | |
group: context.logGroupName, | |
stream: context.logStreamName, | |
filter: `"${context.awsRequestId}"`, | |
start: new Date().toISOString(), | |
}, | |
";", | |
"=", | |
) | |
return url.toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment