Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws cli logs filter-pattern exclude

I'm trying to get logs from an application running in AWS, while excluding logs that contain a certain phrase:

aws logs filter-log-events --log-group-name $MY_LOG_GROUP --filter-pattern -"dont want"

The above works. However, if I instead try:

aws logs filter-log-events --log-group-name $MY_LOG_GROUP --filter-pattern -"dontwant"

I get:

aws: error: argument --filter-pattern: expected one argument

I assume my shell is parsing it as an additional flag, instead of an argument to --filter-pattern. So, first question: How do I force aws cli to treat it as an argument?

If I instead try:

aws logs filter-log-events --log-group-name "$MY_LOG_GROUP" --filter-pattern -"GET /healthcheck"

I get:

An error occurred (InvalidParameterException) when calling the FilterLogEvents operation: Invalid filter pattern

Second question(s): what's the issue here, and how do I fix it?

like image 970
adlaika Avatar asked Oct 25 '25 14:10

adlaika


1 Answers

Try this instead:

aws logs filter-log-events --log-group-name $MY_LOG_GROUP --filter-pattern=-"dont want"

The aws cli supports the <option>=<value> syntax also. Looks like this has been an issue for awhile.

As for the second example, the slash causes issues but I think this works so it will not try to interpret the slash; also an issue for awhile:

aws logs filter-log-events --log-group-name "$MY_LOG_GROUP" --filter-pattern='-"GET /healthcheck"'
like image 153
Brandon Miller Avatar answered Oct 27 '25 13:10

Brandon Miller