You can use the aws cli to get the EKS cluster name, parse the first result and return it into a variable.

This is handy in automation scripts where you need to target the cluster without hardcoding its name. I use this in CI/CD pipelines that deploy to whatever EKS cluster exists in a given region.

EKS_CLUSTER_NAME=$(aws eks list-clusters --region us-west-2 --query clusters[0] --output text)
echo $EKS_CLUSTER_NAME

More on AWS if that’s useful.

The --query clusters[0] grabs the first cluster in the list, so this only works well when you have a single cluster per region. If you have multiple clusters, you’ll want to filter by name pattern or use tags to identify the right one. You can also drop the [0] to get all cluster names and iterate over them.