Skip to content

aws cli describe cluster error using ‘for loop’

I’m having trouble trying to run a for loop with the aws cli command aws eks describe-cluster. I receive the below error on execution. My scripting is not the best. Any help would be greatly appreciated. Thanks.

for i in $(aws eks list-clusters | grep dev-shark); do aws eks describe-cluster --name $i | jq '.cluster.tags."Dev-Ver"'; done

An error occurred (InvalidParameterException) when calling the DescribeCluster operation: The name parameter contains invalid characters. It should begin with letter or digit and can have any of the following characters: the set of Unicode letters, digits, hyphens and underscores.

If I simply run aws eks list-clusters | grep dev-shark it outputs the below:

aws eks list-clusters | grep dev-shark


It seems to be the comma (,) that is causing the error? How best to remove the , at the end of each line?



It is both the comma (,) and the quotation mark (“) that are causing the error. Instead of doing

aws eks list-clusters | grep dev-shark

, you can do

aws eks list-clusters --query 'clusters' --output text | tr 't' 'n' | grep dev-shark
User contributions licensed under: CC BY-SA
3 People found this is helpful