File tree 2 files changed +18
-2
lines changed
src/main/com/codely/lesson_06__deploy_to_cloud/video_01__infra_aws/scripts
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"
14
14
EMR_STEP_FUNCTIONS_ROLE=" EMR_StepFunctions_Role"
15
15
16
16
# Define AWS Account ID
17
- AWS_ACCOUNT_ID=" 010928190667 "
17
+ AWS_ACCOUNT_ID=" CHANGE_FOR_YOUR_AWS_ACCOUNT_ID "
18
18
19
19
# Create S3 bucket
20
20
echo " 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"
14
14
EMR_STEP_FUNCTIONS_ROLE=" EMR_StepFunctions_Role"
15
15
16
16
# 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
+ }
18
31
19
32
# Function to detach and delete IAM policies
20
33
function detach_and_delete_policy() {
@@ -28,6 +41,9 @@ function detach_and_delete_policy() {
28
41
aws iam delete-policy --policy-arn arn:aws:iam::$AWS_ACCOUNT_ID :policy/$policy_name --profile $AWS_PROFILE
29
42
}
30
43
44
+ # Call the function to terminate active EMR clusters
45
+ terminate_active_emr_clusters
46
+
31
47
# Delete EMR Step Functions State Machine
32
48
echo " Deleting Step Functions state machine"
33
49
STATE_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