diff --git a/cleanup/aws_snapshots.sh b/cleanup/aws_snapshots.sh index 889cbb05e..c80a9f431 100755 --- a/cleanup/aws_snapshots.sh +++ b/cleanup/aws_snapshots.sh @@ -54,9 +54,14 @@ if [ -n "${snapshot_ids}" ]; then for snapshot_id in ${snapshot_ids}; do echo "== Attempting to delete snapshot: ${snapshot_id}" - if ! run_aws_ec2_command delete-snapshot --snapshot-id "${snapshot_id}" 2>/dev/null; then - # Log and skip snapshots that are in use - echo "[WARNING] Snapshot ${snapshot_id} is currently in use. Skipping." + if ! output=$(run_aws_ec2_command delete-snapshot --snapshot-id "${snapshot_id}" 2>&1); then + if echo "${output}" | grep -q "InvalidSnapshot.InUse"; then + # Log and skip snapshots that are in use + echo "[WARNING] Snapshot ${snapshot_id} is currently in use. Skipping." + else + # Log unexpected errors + echo "[ERROR] Failed to delete snapshot ${snapshot_id}: ${output}" + fi continue fi echo "== Snapshot ${snapshot_id} successfully deleted."