#!/bin/bash set -e cluster_name=$1 if [ -z "$cluster_name" ]; then echo "Error: You must provide a cluster name" exit 1 fi AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text) nodegroup_output=$(aws eks list-nodegroups --cluster $cluster_name --output json) nodegroup_count=$(echo "$nodegroup_output" | jq '. | length') if [ "$nodegroup_count" != '1' ]; then echo "Error: There should only be 1 node group in the cluster" exit 1 fi default_nodegroup_name=$(echo "$nodegroup_output" | jq '.nodegroups[0]') cat << EOT > /home/ec2-user/.bashrc.d/env.bash aws eks update-kubeconfig --name ${cluster_name} set -a EKS_CLUSTER_NAME=${cluster_name} EKS_DEFAULT_MNG_NAME=${default_nodegroup_name} EKS_DEFAULT_MNG_MIN=3 EKS_DEFAULT_MNG_MAX=6 EKS_DEFAULT_MNG_DESIRED=3 AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID} EKS_IP_FAMILY=ipv4 set +a EOT aws eks update-kubeconfig --name $cluster_name > /dev/null