0

I want the body to go forward, from AWS SNS subscription confirmation is sending POST request to my route of nodejs API but the body is coming empty or undefined

this is a curl request from AWS

curl -X 'POST' 'https://testemails.medixcel.in:5000/api/SESNotifications' -H 'connection: close' -H 'accept-encoding: gzip,deflate' -H 'user-agent: Amazon Simple Notification Service Agent' -H 'host: webhook.site' -H 'content-length: 1525' -H 'content-type: text/plain; charset=UTF-8' -H 'x-amz-sns-topic-arn: arn:aws:sns:ap-south-1:358988201836:medixcelnew' -H 'x-amz-sns-message-id: a27cafbb-ac8b-456a-835b-3c79915eaf68' -H 'x-amz-sns-message-type: SubscriptionConfirmation' -d $'{
  "Type" : "SubscriptionConfirmation",
  "MessageId" : "a27cafbb-ac8b-456a-835b-3c79915eaf68",
  "Token" : "2336412f37fb687f5d51e6e2425c464de63b4730d3a215f236ee1a2ac58cfe38eeb8567e697e09a421d6e7465b283cf57427cc65ac1eadda93c03250599aef69dae60496395586f1eea58bca586ded73f5c0fd9401580863db148fce0c4f4183cba43310475067be6dc3b23176a01253",
  "TopicArn" : "arn:aws:sns:ap-south-1:358988201836:medixcelnew",
  "Message" : "You have chosen to subscribe to the topic arn:aws:sns:ap-south-1:358988201836:medixcelnew.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
  "SubscribeURL" : "https://sns.ap-south-1.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:ap-south-1:358988201836:medixcelnew&Token=2336412f37fb687f5d51e6e2425c464de63b4730d3a215f236ee1a2ac58cfe38eeb8567e697e09a421d6e7465b283cf57427cc65ac1eadda93c03250599aef69dae60496395586f1eea58bca586ded73f5c0fd9401580863db148fce0c4f4183cba43310475067be6dc3b23176a01253",
  "Timestamp" : "2023-03-13T11:35:52.918Z",
  "SignatureVersion" : "1",
  "Signature" : "Pbysx3IgCD/4EzJFsZCuwUW7PsaZb/oO9EK2/woeJH+8FwYaBfmV5NpyBC9mhSGzg0kLJQY6tb9tadIm+7GPDqbNdwzeXUv4AkzydPdof6fomkkmE0XCxGK4NSRn044byBWnMnTGtTv1dOinwUYHaoV5pmX4y3eNBtWPxR7qE4F+zfBqzEcGrtbrDUkZNHn6t5w/3NWappiL/PJoAaZRWiSAQ8kWWq1fVdmwcs9EXEZVP8JJ75R2sSKEzOcQIv3CT96MODTFzcy8ErG0F3jYffbQs28+7mkyAng3IkT1o9oBNndJKGKMFj8DakYYd5EI+UIwubJ6C8jfZNHLgbYJ/Q==",
  "SigningCertURL" : "https://sns.ap-south-1.amazonaws.com/SimpleNotificationService-56e67fcb41f6fec09b0196692625d385.pem"
}'


1 Answers1

0

Here are few steps that might help you, if you are trying to subscribe to SNS with https.

  • First you have to create a post route.
  • Pass that route in AWS Console and select https subscription.
  • When you create the Subscription in AWS with that route AWS sends a verification on that route and here is your code look like, in the payload it contains SubscribeURL you have to hit this URL manually or via code base as i'm doing with node package request you can use request/axios/https whatever you like, i'm using request.
  • After the Get request, it should subscribe successfully.
const express = require("express");
const app = express();
const request = require('request');

app.use(express.text());

app.post("/", (req, res) => {
  const jsonParse = JSON.parse(req.body);
  console.log(jsonParse.SubscribeURL)
  console.log(jsonParse.Type)

  const promise = new Promise((resolve, reject) => {
      const url = jsonParse.SubscribeURL;

      request(url, (err, res) =>{
          if(!err && res.statusCode == 200){
              return resolve();
          }else{
              return reject();
          }
      });

  });
});

app.listen(3000, () => console.log("Server listening on port 3000!"));
hassan
  • 81
  • 4