2015-09-18 98 views
1

我試圖將終端作爲我的網站(http://website.com/),並在成功訂閱後發佈到SNS主題。AWS SNS Invalid Token

無論我嘗試什麼,我都會得到相同的無效令牌錯誤。有人可以幫我嗎? (消毒代碼)

endPointTest() 
    .then((result) => { 
    console.log("Result", result); 

    AWS.config.update({ 
     accessKeyId:'accessKeyIdvalue', 
     secretAccessKey:'secretAccessKeyvalue', 
     region: 'us-west-2' 
    }); 
    var sns = new AWS.SNS(); 
    console.log("SNS OBj", sns); 
    var params2 = { 
     Protocol: 'http', /* required */ 
     TopicArn: 'topic_ARN_from_console', /* required */ 
     Endpoint: 'http://website.com/' 
    }; 
    sns.subscribe(params2, function(err, data) { 
     if (err) console.log(err, err.code); // an error occurred, where it breaks 
     else  { 
     console.log("Subscribing...", data.ResponseMetadata.RequestId);//Prints this 
     console.log("Subscribing... with data", data); //Prints this fine 
     var params1 = { 
      Token: data.ResponseMetadata.RequestId, /* required */ 
      TopicArn: 'topic_ARN_from_console' /* required */ 
      //AuthenticateOnUnsubscribe: 'false' 
     }; 
     sns.confirmSubscription(params1, function(err, data) { 
      if (err) console.log(err, err.stack); // an error occurred 
      else { 
      console.log("Confirmed Sub", data); 
      }   // successful response 
     }); 
     } 
    }); 
    }).catch(console.error.bind(console)); 

錯誤,我得到:

POST https://sns.us-west-2.amazonaws.com/ 400 (Bad Request) 

VideoUploader.js:135錯誤:無效令牌

我要去哪裏錯了?

回答

0

SNS subscribe() documentation表示返回的數據只包含SubscriptionArn。它不包含確認標記。

我相信您正在查找的訂閱確認標記由SNS發送到您在調用subscribe()時指示的端點。這就是SNS如何確認您控制端點的方式。您需要從該端點檢索它,然後通過調用confirmSubscription()將其提供給SNS。

+0

對不起,什麼端點?我怎樣才能得到它(你有代碼示例) – premunk

+0

我擡頭看看我的這個環境,但這似乎沒有幫助! – premunk

+0

你問了哪個端點。這是你的終點;你在你的subscribe()調用中提供的那個。 subscribe()調用通過向端點發送一個確認標記來準備訂閱您的端點。然後您在confirmSubscription()調用中將該令牌提供給SNS。證明您控制端點並且沒有錯誤輸入或類似的內容是一次握手。請參閱http://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html上所述的訂閱操作。 – jarmod