CloudWatchとかの設定を自動でやるときにSNSのトピックのIDを
ハードコーディングするとちょっと使いづらいので一覧でとってきて選択させるようにしてみました。
#!/bin/sh
tmpfile=`mktemp`
aws sns --profile {profile} list-topics | awk '{print $2}' > $tmpfile
if [ ! -f $tmpfile ]; then
echo "sns topic not found"
exit 1
fi
if [ ! -s $tmpfile ]; then
echo "sns topic not found"
exit 1
fi
COUNT=1
for line in `cat $tmpfile`
do
echo "${COUNT} $line"
COUNT=$(( COUNT + 1 ))
done
read -p "please choose sns topic number : " NUMBER_LOADSETTING
SNS=`sed -n -e ${NUMBER_LOADSETTING}p $tmpfile`
if [ "$SNS" = "" ]; then
echo "sns is empty"
exit 1
fi
echo "$SNS"
rm -f $tmpfile


