LoginSignup
1
1

More than 5 years have passed since last update.

Amazon Simple Notification Service

Last updated at Posted at 2018-08-23

AWSのSNS(Amazon Simple Notification Service)について勉強したことをまとめます。

SNS(Amazon Simple Notification Service)とSQS(Amazon Simple Queue Service)はAWSでイベントドリブンアーキテクチャを実現するためのサービスです。

1 SNS

1.1 SNSの概要

特定のサービスへメッセージを送信するためのサービス。
トピックと呼ばれるものを作成してメッセージの送信を行う。
パブリッシャー(メッセージを送信する側)がSNSにメッセージをトピックに登録するとサブスクライバー(メッセージを受信する側)に即時にメッセージを送信する。
SNSはHTTPやEmail、AWSLambdaなどの複数のプロトコルに対応しているのでサブスクライバーにはWEBサーバ、メールアドレスなど色々なものを登録できる。
後述するSQSとも連携可能。
メッセージを瞬時に処理することができ、シンプルな構造でアプリケーションを統合することが可能。

1.2 CLIから操作してみる

1.2.1 トピックの作成

aws sns create-topic --name my_topic

1.2.2 サブスクライバーの設定

メッセージをSNSから受信するサービスの設定を行う。
今回は手軽にEメールを使用するので受信に使用するプロトコルに"email"を指定し、
エンドポイントに使用可能なメールアドレスを指定した。

aws sns subscribe \
--topic-arn arn:aws:sns:ap-northeast-1:[AWSアカウントID]:my_topic \
--protocol email \
--notification-endpoint 〇〇〇〇〇〇〇@〇〇〇〇.〇〇〇

上記コマンドを叩くとこんなメールが届いた。
メールアドレスの確認のためのメールのようです。
Confirm subscriptionのリンクをクリックすればOK。

You have chosen to subscribe to the topic: 
arn:aws:sns:ap-northeast-1:[AWSアカウントID]:my_topic

To confirm this subscription, click or visit the link below (If this was in error no action is necessary): 
Confirm subscription

Please do not reply directly to this email. If you wish to remove yourself from receiving all future SNS subscription confirmation requests please send an email to sns-opt-out

1.2.4 トピックにメッセージ登録

Hello worldというメッセージをSNSに登録してみる

aws sns publish \
--topic-arn arn:aws:sns:ap-northeast-1:[AWSアカウントID]:my_topic \
--subject "test" \
--message "Hello World"

1.2.5 メールの確認

トピックに登録されたメッセージは即時にサブスクライバーに送信されるのでメールを確認してみる。
件名:test
内容:hello world
というメールを受信できていたので動作確認完了です。

1
1
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
1