-1

What would be the most efficient way to EMIT a POST requests (a webhook precisely) from AWS on a daily basis ?

Right away, I started by simply creating a cloudWatch rule with an event schedule CRON that would trigger an SNS publication "every day at 18h", then I created an SNS topic "AlertMyWebhook" with all POST endpoints as subscribers of the topic.

But.. SNS requires me to CONFIRM subscription of each endpoints... which I can't by definition, since the https endpoint is not mine (webhook = HOOK into someone ELSE'S WEBapp).

So now I am starting to think crazy stuff like having a dynamoDB table to store all webhooks endpoint URL, coupled with a lambda function to read the table, take each https endpoints, and send a POST request to them...

Frankly speaking: that doesn't make any sense to me.

Is there any way to avoid SNS confirmation ? If not, how on earth would you do to "trigger a POST every day at 18h" without creating a monolithic-like architecture ?

Jona Rodrigues
  • 992
  • 1
  • 11
  • 23
  • Conceptually you want something like [this](https://stackoverflow.com/questions/47077829/send-post-request-to-an-external-api-using-aws-lambda-in-python)? This is SNS to Lambda to a POST. It removes the need to confirm the subscription. Slightly harder but pretty close. – stdunbar Jan 08 '18 at 02:44
  • Thanks for the reply. The link you provided does not explain SNS > LAMBDA > POST I am afraid :) So I don't really see what you mean. – Jona Rodrigues Jan 08 '18 at 03:27

1 Answers1

1

AWS SNS and Lambda functions are integrated with each other so you can subscribe a Lambda function to your topic. When a message is posted to that topic the subscribed Lambda function is invoked with the Payload(published message).

Using this Payload as input for the Lambda function trigger the POST requests for the endpoints. A good way to do is make all the HTTPS POST endpoints as Environment variables in Lambda. So there is no code change in the Lambda function whenever a new POST endpoint need to be added as the Subscription endpoints. For more of How to integrate AWS SNS and Lambda look here.

Invoking Lambda functions using Amazon SNS notifications

The sample NodeJS code to invoke the POST request

AWS Lambda HTTP POST Request

Vaisakh PS
  • 1,181
  • 2
  • 10
  • 19
  • Thanks for the reply. Much appreciated. I didn't know about the payload, I just discovered it with your insights, thanks. However, I don't really understand this: "make all the HTTPS POST endpoints as Environment variables in Lambda" ? How does it interact with the SNS payload ? It got me confused. – Jona Rodrigues Jan 09 '18 at 12:00
  • @JonaRodrigues rather than hardcoding the subscribers endpoints inside the Lambda code, use it's env variables for adding/removing the subscribers. – Vaisakh PS Jan 11 '18 at 08:55