saw icon indicating copy to clipboard operation
saw copied to clipboard

feat: add fuzzy searching for log group names

Open a-h opened this issue 1 year ago • 1 comments

When you're building Lambda functions with CDK, you can't always guess the log prefix, and even if you can, it's a bit unweildy.

For example, with a CDK stack with logical ID "NodeCountExampleAwsLambdaStack" and a Lambda function called "CountGetFunction", CDK generates a CloudWatch Log Group of:

/aws/lambda/NodeCountExampleAwsLambda-CountGetFunctionD35D8410-

Note how "NodeCountExampleAwsLambdaStack" is truncated to "NodeCountExampleAwsLambda". There are also limits on the function logical ID.

To save me from having to use saw groups | grep CountGet, then copy / paste the outputted group name so that I can run saw get <groupname>, I thought it would be helpful to be able to "fuzzy search" the group name.

So in this PR, I've implemented a basic "contains substring" search for the log group that's only triggered when a --fuzzy flag is set.

You can get the logs directly with:

saw --fuzzy CountGet

Compared to:

saw get /aws/lambda/NodeCountExampleAwsLambda-CountGetFunctionD35D8410....

Obviously, it costs a CloudWatch Log API call or two if you use the fuzzy search flag, but it's not the default behaviour so won't affect anyone that doesn't use it.

a-h avatar Sep 05 '22 13:09 a-h

very nice -- I will take a look when I get some time to do so, thank you

TylerBrock avatar Sep 06 '22 12:09 TylerBrock