Skip to content

Commit

Permalink
Add EMR deletion to script
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Herrera committed Aug 12, 2024
1 parent 4cdd58a commit 2d0bae7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down

0 comments on commit 2d0bae7

Please sign in to comment.