LoginSignup
1
0

More than 1 year has passed since last update.

Amazon SNSのUnsubscribeリンク無効化する( + 無効化の確認まで)

Last updated at Posted at 2023-05-14

概要

Amazon SNSのメール通知では、本文内に記載がある「Unsubscribe」をクリックすると簡単に通知が解除されてしまいます。
知らずに誰かが解除してしまい、メールが届かない事に気づかないというケースは割とあるので、この無効化リンクを解除しておきましょう。

項目

下記を紹介します。

1.コンソールから行う無効化
2.AWS CLIで行う無効化
3.無効化されているか確認する方法

1.コンソールから行う無効化

メールアドレスの新規追加時の前提で進めます。
まず、コンソールからSNSのトピックに対してメールアドレスを設定すると、設定されたメールアドレスに対して下記内容の承認メールが届きます。

件名:
AWS Notification - Subscription Confirmation

本文:
メール1_20230513053422.png

本文に「Confirm subscription」というリンクがありますが、
こちらは左クリックはせず(重要!)、右クリックでリンクのURLを取得しておきましょう。

左クリックで先に承認してしまった場合は、コンソールでのリンクの無効化は出来なくなってしまう模様。

次にコンソールに戻ります。
対象のトピックより、新規追加したサブスクリプションを選択し、「サブスクリプションの確認」を押下。

トピック1_20230513054310.png

ここに先ほど取得しておいたリンクを入れ込んで「確認」を押せば完了です。

トピック2_20230513054615.png

2.CLIから行う無効化

こちらはコンソール手順とは違い、既に承認されているサブスクリプションに対しても(上述した左クリックをしていても)、リンクの無効化が可能です。
CloudShellから実行するのが良いでしょう。

topic-arn、tokenについては、設定対象から取得して入れ込みましょう。
取得方法は次の項目で説明します。

aws sns confirm-subscription \
--topic-arn arn:aws:sns:ap-northeast-1:xxxxxxxxxxxx:zenden_topic \
--token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
--authenticate-on-unsubscribe true \
--region ap-northeast-1

topic-arn、tokenの見つけ方

topic-arn、tokenは、上述の「コンソールから行う無効化」にて取得したURLを見ると確認する事ができます。
例えば下記のようなURLであった場合、このように分けられます。

https://sns.ap-northeast-1.amazonaws.com/confirmation.html?TopicArn=arn:aws:sns:ap-northeast-?:xxxxxxxxxxxx:zenden&Token=2336xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxd8a&Endpoint=zenden@hoge.jp

・topic-arn

arn:aws:sns:ap-northeast-?:xxxxxxxxxxxx:zenden

・token

2336xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxd8a

3.無効化が行われているか確認

CloudShellにて下記コマンドを実行すると確認できます。(このまま実行でOK)
結果を確認して、行頭にTrueと出ていれば無効化されています。

echo '"ConfirmationWasAuthenticated","SubscriptionArn","Protocol","Endpoint"' &&\
  aws sns list-subscriptions | jq -r '.Subscriptions[].SubscriptionArn'\
  | xargs -I{} -P 5 aws sns get-subscription-attributes --subscription-arn {}\
  | jq -r '.Attributes |  [.ConfirmationWasAuthenticated,.SubscriptionArn,.Protocol,.Endpoint] | @csv'

終わりに

時と場合によりますが、特にメーリングリストの場合などは設定しておくと良いのではないかと思います。
誰かのお役に立てば。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0