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 "dev-shark-01-eks-cluster", "dev-shark-02-eks-cluster", "dev-shark-03-eks-cluster"
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