-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.sh
More file actions
executable file
·75 lines (62 loc) · 2.1 KB
/
Copy pathcleanup.sh
File metadata and controls
executable file
·75 lines (62 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
set -e
echo "🧹 Cleaning up AWS resources..."
echo ""
# Load environment variables from .env
if [ ! -f .env ]; then
echo "❌ Error: .env file not found"
echo " Cannot determine which resources to delete."
echo " Please run ./setup.sh first or create .env manually."
exit 1
fi
echo "📝 Loading configuration from .env file..."
source .env
echo ""
# Verify required variables are set
if [ -z "$SNS_TOPIC_ARN" ] || [ -z "$SQS_QUEUE_URL" ]; then
echo "❌ Error: Required variables not found in .env"
echo " Expected: SNS_TOPIC_ARN and SQS_QUEUE_URL"
exit 1
fi
echo "📌 Resources to delete:"
echo " SNS Topic ARN: $SNS_TOPIC_ARN"
echo " SQS Queue URL: $SQS_QUEUE_URL"
echo ""
# Unsubscribe and delete SNS topic
if [ ! -z "$SNS_TOPIC_ARN" ]; then
echo "📢 Deleting SNS subscriptions and topic..."
# Get all subscriptions for the topic
SUBSCRIPTIONS=$(aws sns list-subscriptions-by-topic --topic-arn $SNS_TOPIC_ARN --query 'Subscriptions[*].SubscriptionArn' --output text 2>/dev/null || echo "")
# Unsubscribe each
for SUB_ARN in $SUBSCRIPTIONS; do
if [ "$SUB_ARN" != "PendingConfirmation" ]; then
aws sns unsubscribe --subscription-arn $SUB_ARN 2>/dev/null || true
echo " Deleted subscription: $SUB_ARN"
fi
done
# Delete topic
aws sns delete-topic --topic-arn $SNS_TOPIC_ARN 2>/dev/null || true
echo " Deleted topic: $SNS_TOPIC_ARN"
echo ""
fi
# Delete SQS queue
if [ ! -z "$SQS_QUEUE_URL" ]; then
echo "📦 Deleting SQS queue..."
aws sqs delete-queue --queue-url $SQS_QUEUE_URL 2>/dev/null || true
echo " Deleted queue: $SQS_QUEUE_URL"
echo ""
fi
# Remove .env file
if [ -f .env ]; then
rm .env
echo "📝 Removed .env file"
echo ""
fi
echo "✅ Cleanup complete!"
echo ""
echo "Note: It may take up to 60 seconds for queues to be fully deleted."
echo ""
echo "💡 If you sourced .env in your shell, you can unset the variables with:"
echo " unset SNS_TOPIC_ARN SQS_QUEUE_URL"
echo ""
echo " Or run: source <(echo 'unset SNS_TOPIC_ARN SQS_QUEUE_URL')"