Python (re)

CloudWatch Log Stream Path in PY

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

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"\/aws\/(?:lambda|ecs|eks|apigateway|codebuild|stepfunctions|rds|cloudtrail)\/[\w\-.\/]+")
input_text = "Group: /aws/lambda/api-gateway-handler"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

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)