-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlambda-cleanup.sh
More file actions
executable file
·39 lines (29 loc) · 1.27 KB
/
lambda-cleanup.sh
File metadata and controls
executable file
·39 lines (29 loc) · 1.27 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
#!/bin/sh
ebspolicyarn=`aws iam list-policies --query "Policies[?PolicyName=='makesnap3-policy'].Arn" --output text`
echo Policy: $ebspolicyarn
[ -z $ebspolicyarn ] && read -p "press ^C to stop ..." null
functionarn=`aws events list-targets-by-rule --rule makesnap-daily --query "Targets[0].Arn" --output=text`
echo Function: $functionarn
[ -z $functionarn ] && read -p "press ^C to stop ..." null
echo
echo Deleting roles, policies, function..
echo
aws iam detach-role-policy --role-name ebs-snapshot --policy-arn "$ebspolicyarn"
aws iam detach-role-policy --role-name ebs-snapshot --policy-arn "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
aws iam delete-role --role-name ebs-snapshot
aws iam delete-policy --policy-arn "$ebspolicyarn"
aws lambda delete-function --function-name makesnap3
echo
echo Deleting rules
echo
for period in hourly daily weekly monthly yearly; do
echo "makesnap-${period}"
aws events list-targets-by-rule --rule makesnap-${period}
if [ $? != 0 ]; then
echo No makesnap-${period} rule
else
aws events remove-targets --rule "makesnap-${period}" --ids 1 --query FailedEntryCount --output text
aws events delete-rule --name "makesnap-${period}" --query FailedEntries --output text
fi
done
echo Done