3030
3131touch ~ /.bashrc.d/workshop-env.bash
3232
33+ REPOSITORY_OWNER=${REPOSITORY_OWNER:- " aws-samples" }
34+ REPOSITORY_NAME=${REPOSITORY_NAME:- " eks-workshop-v2" }
35+ REPOSITORY_REF=${REPOSITORY_REF:- " main" }
36+
3337cat << EOT > /home/ec2-user/.bashrc.d/aliases.bash
3438function prepare-environment() {
3539 start_time=\$ (date +%s)
40+
41+ if [[ "\$ 1" == fastpaths/* ]]; then
42+ cluster_name="\$ EKS_CLUSTER_AUTO_NAME"
43+ create_cmd="create-cluster-auto"
44+ else
45+ cluster_name="\$ EKS_CLUSTER_NAME"
46+ create_cmd="create-cluster"
47+ fi
48+
49+ if ! aws eks describe-cluster --name "\$ cluster_name" --no-cli-pager &>/dev/null; then
50+ echo "Error: EKS cluster '\$ cluster_name' does not exist."
51+ echo "Please create it first by running: \$ create_cmd"
52+ return 1
53+ fi
54+
3655 bash /usr/local/bin/reset-environment \$ 1
3756 exit_code=\$ ?
3857 source ~/.bashrc.d/workshop-env.bash
@@ -41,13 +60,12 @@ function prepare-environment() {
4160}
4261
4362function use-cluster() { bash /usr/local/bin/use-cluster \$ 1; source ~/.bashrc.d/env.bash; }
44- function create-cluster() { URL=https://raw.githubusercontent.com/${REPOSITORY_OWNER} /${REPOSITORY_NAME} /refs/heads/${REPOSITORY_REF} /cluster/eksctl/cluster.yaml; echo "Creating cluster with eksctl from $URL "; curl -fsSL $URL | envsubst | eksctl create cluster -f -; }
45- function create-cluster-auto() { URL=https://raw.githubusercontent.com/${REPOSITORY_OWNER} /${REPOSITORY_NAME} /refs/heads/${REPOSITORY_REF} /cluster/eksctl/cluster-auto.yaml; echo "Creating cluster with eksctl from $URL "; curl -fsSL $URL | envsubst | eksctl create cluster -f -; }
63+ function create-cluster() { URL=https://raw.githubusercontent.com/\$ {REPOSITORY_OWNER}/\$ {REPOSITORY_NAME}/refs/heads/\$ {REPOSITORY_REF}/cluster/eksctl/cluster.yaml; echo "Creating cluster with eksctl from \$ URL"; curl -fsSL \$ URL | envsubst | eksctl create cluster -f -; }
64+ function create-cluster-auto() { URL=https://raw.githubusercontent.com/\$ {REPOSITORY_OWNER}/\$ {REPOSITORY_NAME}/refs/heads/\$ {REPOSITORY_REF}/cluster/eksctl/cluster-auto.yaml; echo "Creating cluster with eksctl from \$ URL"; curl -fsSL \$ URL | envsubst | eksctl create cluster -f -; }
65+ function delete-cluster() { URL=https://raw.githubusercontent.com/\$ {REPOSITORY_OWNER}/\$ {REPOSITORY_NAME}/refs/heads/\$ {REPOSITORY_REF}/cluster/eksctl/cluster.yaml; echo "Creating cluster with eksctl from \$ URL"; curl -fsSL \$ URL | envsubst | eksctl delete cluster -f -; }
66+ function delete-cluster-auto() { URL=https://raw.githubusercontent.com/\$ {REPOSITORY_OWNER}/\$ {REPOSITORY_NAME}/refs/heads/\$ {REPOSITORY_REF}/cluster/eksctl/cluster-auto.yaml; echo "Creating cluster with eksctl from \$ URL"; curl -fsSL \$ URL | envsubst | eksctl delete cluster -f -; }
4667EOT
4768
48- REPOSITORY_OWNER=${REPOSITORY_OWNER:- " aws-samples" }
49- REPOSITORY_NAME=${REPOSITORY_NAME:- " eks-workshop-v2" }
50-
5169if [ ! -z " $REPOSITORY_REF " ]; then
5270 cat << EOT > ~/.bashrc.d/repository.bash
5371export REPOSITORY_OWNER='${REPOSITORY_OWNER} '
0 commit comments