i have a simple script that i want to display specific information from AWS using AWS CLI.
for example:
get_cluster_name() {
EKS_NAME=$(aws eks describe-cluster --name ${CUSTOMER_NAME}) && \
echo $EKS_NAME | jq -r .cluster.name}
the output when the cluster exist is ok, i get the name of the cluster.
when the cluster does not exist, i get:
An error occurred (ResourceNotFoundException) when calling the DescribeCluster operation: No cluster found for name: example_cluster.
my goal is to get an empty output when a cluster is not found. for that i wanted to use the return code in a condition or a string lookup in the output.
the issue is that the output is not stdout or stderr, therefor i cant even direct it to /dev/null just to silence the error.
how can i make this code work properly?:
[[ $(get_cluster_name) =~ "ResourceNotFoundException" ]] && echo "EKS Cluster:....$(get_cluster_name)"
or
[[ $(get_cluster_name) ]] && echo "EKS Cluster:....$(get_cluster_name)"
Thank you.