Skip to content
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d9be596
list mq configurations
siddavamshi4 Jul 15, 2025
40c746f
Update delete-mq-configs.yml
siddavamshi4 Jul 15, 2025
6e262c2
with test on pushes
siddavamshi4 Jul 17, 2025
e196b42
Update delete-mq-configs.yml
siddavamshi4 Jul 17, 2025
437dd71
Update delete-mq-configs.yml
siddavamshi4 Jul 17, 2025
e3b4608
aws login with secrets
siddavamshi4 Jul 17, 2025
18418b2
with query changes
siddavamshi4 Jul 17, 2025
a6cf0d8
test run to check deletions
siddavamshi4 Jul 17, 2025
5c5945f
with no pagination
siddavamshi4 Jul 17, 2025
9f2b4d5
test run with retention_days as 1000
siddavamshi4 Jul 17, 2025
5978c35
test to get count
siddavamshi4 Jul 17, 2025
56718d8
test to remove pagination
siddavamshi4 Jul 17, 2025
eb368ba
testing pagination
siddavamshi4 Jul 17, 2025
7c1ab54
with --max-results
siddavamshi4 Jul 17, 2025
2d190a1
test pagination with --max-results
siddavamshi4 Jul 17, 2025
b16e755
testing listing with a script
siddavamshi4 Jul 18, 2025
d1b60cc
running tests with pagination
siddavamshi4 Jul 18, 2025
ae19d6f
test with prefix molecule-
siddavamshi4 Jul 18, 2025
8b40018
testing break after 20 reocrds
siddavamshi4 Jul 18, 2025
b8dd3ce
testing to delete 20 records
siddavamshi4 Jul 18, 2025
2436231
test deletion of 20 records
siddavamshi4 Jul 18, 2025
a84a54a
with scheduled deletion of AWS mq
siddavamshi4 Jul 18, 2025
e8ace43
with AWS OIDC authentication
siddavamshi4 Jul 21, 2025
52ed0ff
optimized job
siddavamshi4 Jul 21, 2025
3c5ee85
with aws_region env variable
siddavamshi4 Jul 22, 2025
c20a6fb
with dry- run configuration
siddavamshi4 Jul 22, 2025
96747d2
removed extra space
siddavamshi4 Jul 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/aws-mq-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Cleanup MQ Configurations

on:
workflow_dispatch:
inputs:
dry_run:
type: boolean
default: true
description: "If true, skips deletion for safe testing"
schedule:
- cron: '23 5 1 * *'

permissions:
id-token: write
contents: read

env:
RETENTION_DAYS: 30
AWS_REGION: eu-west-1
DRY_RUN: ${{ inputs.dry_run && github.event_name != 'schedule' }}

jobs:
delete-mq-configs:
runs-on: ubuntu-latest
steps:
- name: Login to AWS
uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::372466110691:role/AlfrescoCI/mq-configuration-cleanup
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}
role-duration-seconds: 1800

- name: Delete old MQ configurations (using pagination)
run: |
set -o pipefail
threshold_epoch=$(date -d "$RETENTION_DAYS days ago" +"%s")
next_token=""

echo "Checking for MQ configurations older than $RETENTION_DAYS days..."

while true; do
list_configurations_cmd="aws mq list-configurations --max-results 100 --output json"

if [ -z "$next_token" ]; then
response=$($list_configurations_cmd)
else
response=$($list_configurations_cmd --next-token "$next_token")
fi

configs=$(echo "$response" | jq -c '.Configurations[]?')
next_token=$(echo "$response" | jq -r '.NextToken')

while read -r config; do
id=$(jq -r '.Id' <<< "$config")
name=$(jq -r '.Name' <<< "$config")

if [[ "$name" != molecule-* ]]; then
echo "Skipping: $name (ID: $id) — doesn't match prefix 'molecule-'"
continue
fi

created=$(jq -r '.LatestRevision.Created' <<< "$config")
created_epoch=$(date -d "${created%%.*}" +"%s")

age_days=$(( ( $(date -u +"%s") - created_epoch ) / 86400 ))

attached=$(aws mq list-brokers \
--query "BrokerSummaries[?Configuration.Id=='$id'].BrokerId" \
--output text)

if [ -n "$attached" ]; then
echo "In use: $name ($id) — broker: $attached"
continue
fi

if [ "$created_epoch" -lt "$threshold_epoch" ]; then
if [ "$DRY_RUN" = "false" ]; then
echo "Deleting: $name ($id) — $age_days days old"
aws mq delete-configuration --configuration-id "$id"
else
echo "Dry run would delete: $name ($id) — $age_days days old"
fi
else
echo "Keeping: $name ($id) — $age_days days old"
fi
done < <(echo "$configs")

# Exit loop if no more pages
[ "$next_token" == "null" ] || [ -z "$next_token" ] && break
done