CloudWatch Log Stream Path in JS
Match AWS CloudWatch log group / stream paths like `/aws/lambda/my-function` or `/aws/ecs/cluster-name`.
Try it in the JS tester →Pattern
regexJS
\/aws\/(?:lambda|ecs|eks|apigateway|codebuild|stepfunctions|rds|cloudtrail)\/[\w\-.\/]+ (flags: g)JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("\\/aws\\/(?:lambda|ecs|eks|apigateway|codebuild|stepfunctions|rds|cloudtrail)\\/[\\w\\-.\\/]+", "g");
const input = "Group: /aws/lambda/api-gateway-handler";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
Anchors on the AWS-managed log group prefix `/aws/`, then a known service name from the alternation, then the resource path. The character class [\w\-.\/] allows word chars, hyphens, dots, and slashes — covering nested paths like `/aws/lambda/prod-handler/2024/01/15`.
Examples
Input
Group: /aws/lambda/api-gateway-handlerMatches
/aws/lambda/api-gateway-handler
Input
/aws/ecs/my-cluster/web-serviceMatches
/aws/ecs/my-cluster/web-service
Input
/myapp/custom/logsNo match
—