File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ EMR_STEP_FUNCTIONS_POLICY="EMR_StepFunctions_Policy"
1414EMR_STEP_FUNCTIONS_ROLE=" EMR_StepFunctions_Role"
1515
1616# Define AWS Account ID
17- AWS_ACCOUNT_ID=" 010928190667 "
17+ AWS_ACCOUNT_ID=" CHANGE_FOR_YOUR_AWS_ACCOUNT_ID "
1818
1919# Create S3 bucket
2020echo " Creating S3 bucket: $S3_BUCKET_NAME "
Original file line number Diff line number Diff line change @@ -14,7 +14,20 @@ EMR_STEP_FUNCTIONS_POLICY="EMR_StepFunctions_Policy"
1414EMR_STEP_FUNCTIONS_ROLE=" EMR_StepFunctions_Role"
1515
1616# Define AWS Account ID
17- AWS_ACCOUNT_ID=" 010928190667"
17+ AWS_ACCOUNT_ID=" CHANGE_FOR_YOUR_AWS_ACCOUNT_ID"
18+
19+ # Function to terminate active EMR clusters
20+ function terminate_active_emr_clusters() {
21+ echo " Listing active EMR clusters"
22+ local cluster_ids=$( aws emr list-clusters --active --query ' Clusters[*].Id' --output text --profile $AWS_PROFILE )
23+
24+ if [ -n " $cluster_ids " ]; then
25+ echo " Terminating active EMR clusters: $cluster_ids "
26+ aws emr terminate-clusters --cluster-ids $cluster_ids --profile $AWS_PROFILE
27+ else
28+ echo " No active EMR clusters found."
29+ fi
30+ }
1831
1932# Function to detach and delete IAM policies
2033function detach_and_delete_policy() {
@@ -28,6 +41,9 @@ function detach_and_delete_policy() {
2841 aws iam delete-policy --policy-arn arn:aws:iam::$AWS_ACCOUNT_ID :policy/$policy_name --profile $AWS_PROFILE
2942}
3043
44+ # Call the function to terminate active EMR clusters
45+ terminate_active_emr_clusters
46+
3147# Delete EMR Step Functions State Machine
3248echo " Deleting Step Functions state machine"
3349STATE_MACHINE_ARN=$( aws stepfunctions list-state-machines --profile $AWS_PROFILE --query " stateMachines[?name=='EMR_StepFunctions_Machine'].stateMachineArn" --output text)
You can’t perform that action at this time.
0 commit comments