Go (RE2)

CloudWatch Log Stream Path in GO

Match AWS CloudWatch log group / stream paths like `/aws/lambda/my-function` or `/aws/ecs/cluster-name`.

Try it in the GO tester →

Pattern

regexGO
\/aws\/(?:lambda|ecs|eks|apigateway|codebuild|stepfunctions|rds|cloudtrail)\/[\w\-.\/]+   (flags: g)

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`\/aws\/(?:lambda|ecs|eks|apigateway|codebuild|stepfunctions|rds|cloudtrail)\/[\w\-.\/]+`)
	input := `Group: /aws/lambda/api-gateway-handler`
	for _, match := range re.FindAllString(input, -1) {
		fmt.Println(match)
	}
}

Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.

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-handler

Matches

  • /aws/lambda/api-gateway-handler

Input

/aws/ecs/my-cluster/web-service

Matches

  • /aws/ecs/my-cluster/web-service

Input

/myapp/custom/logs

No match

Same pattern, other engines

← Back to CloudWatch Log Stream Path overview (all engines)