LoginSignup
7
6

More than 5 years have passed since last update.

【AWS SDK for PHP】AWS SNSでHTTPエンドポイントへの受信確認するまでの簡単なメモ

Posted at

前提

  • エンドポイントとなるWebサーバが準備出来ていること
  • 以下のコードが実行可能な状態であること
    • AWS SDK for PHPがインストール済み

<?php

require 'vendor/autoload.php';
use Aws\Sns\SnsClient;

$sns = new SnsClient([
  'region' => 'ap-northeast-1',
  'version' => '2010-03-31'
]);

$json_string = file_get_contents('php://input');
$obj = json_decode($json_string);

# 受けとったTokenでサブスクリプションの確認を実行
$sns->confirmSubscription([
        'Token' => $obj->{"Token"},
        'TopicArn' => $obj->{"TopicArn"}
]);

手順メモ

  1. マネジメントコンソールで「新しいトピックの作成」
  2. 適当にトピック名を指定して、作成
  3. 作成されたトピックのARNをクリック
  4. 「トピックの詳細:」画面に遷移する
  5. 「サブスクリプションの作成」をクリック
  6. 「プロトコル」をHTTP,エンドポイントにWebサーバのIPアドレスを入力し、「サブスクリプションの作成」をクリック
  7. 作成されたサブスクリプションを選択し、「リクエストの確認」をクリック
  8. 上記PHPが実行され、サブスクリプションが有効となる。成功すれば「サブスクリプションID」が発行される

サブスクリプションの認証時にPOSTされるデータ形式メモ

{
  "Type" : "SubscriptionConfirmation",
  "MessageId" : "XXXXXX",
  "Token" : "XXXXXXX",
  "TopicArn" : "arn:aws:sns:ap-northeast-1:xxxxxxxx:xxxxxx",
  "Message" : "xxxxxx.",
  "SubscribeURL" : "https://sns.ap-northeast-1.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:ap-northeast-1:xxxxxxx:xxxxxxx",
  "Timestamp" : "2018-11-29Txxxxxxxx",
  "SignatureVersion" : "1",
  "Signature" : "XXXXXXXXXXXX",
  "SigningCertURL" : "https://sns.ap-northeast-1.amazonaws.com/SimpleNotificationService-xxxxxxxx.pem"
}2

参考

HTTP/HTTPS エンドポイントへの Amazon SNS メッセージの送信 - Amazon Simple Notification Service https://docs.aws.amazon.com/ja_jp/sns/latest/dg/SendMessageToHttp.html

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