diff --git a/src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts/1-setup-resources.sh b/src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts/1-setup-resources.sh index 53743dd..06fec93 100644 --- a/src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts/1-setup-resources.sh +++ b/src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts/1-setup-resources.sh @@ -14,7 +14,7 @@ EMR_STEP_FUNCTIONS_POLICY="EMR_StepFunctions_Policy" EMR_STEP_FUNCTIONS_ROLE="EMR_StepFunctions_Role" # Define AWS Account ID -AWS_ACCOUNT_ID="010928190667" +AWS_ACCOUNT_ID="CHANGE_FOR_YOUR_AWS_ACCOUNT_ID" # Create S3 bucket echo "Creating S3 bucket: $S3_BUCKET_NAME" diff --git a/src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts/2-cleanup-resources.sh b/src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts/2-cleanup-resources.sh index c6d8b87..be68e48 100644 --- a/src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts/2-cleanup-resources.sh +++ b/src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts/2-cleanup-resources.sh @@ -14,7 +14,20 @@ EMR_STEP_FUNCTIONS_POLICY="EMR_StepFunctions_Policy" EMR_STEP_FUNCTIONS_ROLE="EMR_StepFunctions_Role" # Define AWS Account ID -AWS_ACCOUNT_ID="010928190667" +AWS_ACCOUNT_ID="CHANGE_FOR_YOUR_AWS_ACCOUNT_ID" + +# Function to terminate active EMR clusters +function terminate_active_emr_clusters() { + echo "Listing active EMR clusters" + local cluster_ids=$(aws emr list-clusters --active --query 'Clusters[*].Id' --output text --profile $AWS_PROFILE) + + if [ -n "$cluster_ids" ]; then + echo "Terminating active EMR clusters: $cluster_ids" + aws emr terminate-clusters --cluster-ids $cluster_ids --profile $AWS_PROFILE + else + echo "No active EMR clusters found." + fi +} # Function to detach and delete IAM policies function detach_and_delete_policy() { @@ -28,6 +41,9 @@ function detach_and_delete_policy() { aws iam delete-policy --policy-arn arn:aws:iam::$AWS_ACCOUNT_ID:policy/$policy_name --profile $AWS_PROFILE } +# Call the function to terminate active EMR clusters +terminate_active_emr_clusters + # Delete EMR Step Functions State Machine echo "Deleting Step Functions state machine" STATE_MACHINE_ARN=$(aws stepfunctions list-state-machines --profile $AWS_PROFILE --query "stateMachines[?name=='EMR_StepFunctions_Machine'].stateMachineArn" --output text)