-
Notifications
You must be signed in to change notification settings - Fork 20
Clean up lingering clusters after test runs #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/bin/bash | ||
|
|
||
| if [ -z "${IS_CI}" ]; then | ||
| echo "Error: This script is intended to run only in CI environments." | ||
| echo "Running it locally may delete clusters in your account." | ||
| echo "Set the IS_CI environment variable to run this script." | ||
| exit 1 | ||
| fi | ||
|
|
||
| REGIONS=("us-east-1" "us-east-2") | ||
|
|
||
| # Region and cluster ID can be extracted from ARN | ||
| # ARN format: arn:aws:dsql:REGION:ACCOUNT:cluster/CLUSTER_ID | ||
| declare -a ARNS=() | ||
| declare -a FILTERED_ARNS=() | ||
|
|
||
| # Get clusters from each region and extract ARNs | ||
| for region in "${REGIONS[@]}"; do | ||
| echo "Listing clusters in $region..." | ||
|
|
||
| region_arns=$(aws dsql list-clusters --region "$region" | jq -r '.clusters[].arn') | ||
|
|
||
| # Add ARNs to the array if any were found | ||
| if [ -n "$region_arns" ]; then | ||
| while IFS= read -r arn; do | ||
| ARNS+=("$arn") | ||
| done <<< "$region_arns" | ||
| fi | ||
| done | ||
|
|
||
| echo -e "\nFound ${#ARNS[@]} cluster(s) across all regions:" | ||
| printf '%s\n' "${ARNS[@]}" | ||
|
|
||
| echo -e "\nFiltering clusters..." | ||
| for arn in "${ARNS[@]}"; do | ||
| region=$(echo "$arn" | cut -d':' -f4) | ||
| cluster_id=$(echo "$arn" | cut -d'/' -f2) | ||
|
|
||
| echo "Checking cluster $cluster_id in region $region..." | ||
|
|
||
| cluster_details=$(aws dsql get-cluster --region "$region" --identifier "$cluster_id") | ||
|
|
||
| status=$(echo "$cluster_details" | jq -r '.status') | ||
| repo_tag=$(echo "$cluster_details" | jq -r '.tags.Repo // empty') | ||
|
|
||
| # We only want clusters that are not already deleting, and have the specific repo tag | ||
| if [[ "$status" != "DELETED" && "$status" != "DELETING" && "$repo_tag" == "aws-samples/aurora-dsql-samples" ]]; then | ||
| echo "Cluster $cluster_id qualifies for update (Status: $status, Repo tag: $repo_tag)" | ||
| FILTERED_ARNS+=("$arn") | ||
| else | ||
| echo "Skipping cluster $cluster_id (Status: $status, Repo tag: $repo_tag)" | ||
| fi | ||
| done | ||
|
|
||
| echo -e "\nFound ${#FILTERED_ARNS[@]} cluster(s) that will be updated and deleted:" | ||
| printf '%s\n' "${FILTERED_ARNS[@]}" | ||
|
|
||
| # Early exit if no clusters to update | ||
| if [ ${#FILTERED_ARNS[@]} -eq 0 ]; then | ||
| echo -e "\nNo clusters to update or delete. Exiting." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo -e "\nUpdating filtered clusters to disable deletion protection..." | ||
| for arn in "${FILTERED_ARNS[@]}"; do | ||
| region=$(echo "$arn" | cut -d':' -f4) | ||
| cluster_id=$(echo "$arn" | cut -d'/' -f2) | ||
|
|
||
| echo "Updating cluster $cluster_id in region $region..." | ||
| aws dsql update-cluster --region "$region" --identifier "$cluster_id" --no-deletion-protection-enabled | ||
| echo "Cluster $cluster_id updated successfully." | ||
| done | ||
|
|
||
| echo -e "\nDeleting filtered clusters..." | ||
| for arn in "${FILTERED_ARNS[@]}"; do | ||
| region=$(echo "$arn" | cut -d':' -f4) | ||
| cluster_id=$(echo "$arn" | cut -d'/' -f2) | ||
|
|
||
| echo "Deleting cluster $cluster_id in region $region..." | ||
| aws dsql delete-cluster --region "$region" --identifier "$cluster_id" | ||
| echo "Deletion initiated for cluster $cluster_id." | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: Clean up Aurora DSQL Clusters | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| aws_region: | ||
| required: false | ||
| type: string | ||
| default: 'us-east-1' | ||
| description: 'Default AWS region for credentials, does not limit access to other regions' | ||
| secrets: | ||
| AWS_IAM_ROLE: | ||
| required: true | ||
| description: 'AWS IAM role to assume for cluster cleanup' | ||
|
|
||
| jobs: | ||
| cleanup: | ||
| name: Clean up Aurora DSQL Clusters | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Update AWS CLI to latest version | ||
| run: | | ||
| curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
| unzip -q awscliv2.zip | ||
| sudo ./aws/install --update | ||
| aws --version | ||
|
|
||
| - name: Configure AWS Credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: ${{ secrets.AWS_IAM_ROLE }} | ||
| aws-region: ${{ inputs.aws_region }} | ||
|
|
||
| - name: Run cluster cleanup script | ||
| env: | ||
| IS_CI: "true" | ||
| run: .github/scripts/clean-clusters.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.