2

I want to send SMS via AWS SNS service but not by using AWS Lambda instead I want to do following

  1. Use API Gateway
  2. use the AWS Services options
  3. select SNS directly not lambda ( why do I need lambda ? )
  4. Call the API Gateway from the mobile app.

Is this possible? I think it should be but don't see much documentation on this and most of the people are forcefully using lambda!

TheParam
  • 10,113
  • 4
  • 40
  • 51
Satendra Negi
  • 44
  • 1
  • 5

1 Answers1

2

The problem is that you need to execute some code somewhere to actually execute the "send SMS" action. This is why Lambda functions are a good fit: they run code and you don't manage servers. But of course, you're not obliged to use them.

You can easily hook an API Gateway Endpoint with SNS, but then you need to process the message that has arrived in SNS via a Subscriber (this is where Lambda kicks in), otherwise, what would you do with a message that nobody can consume? You have a few options to subscribe to your SNS topic, but Lambda is the easiest. But let's say you don't want to use Lambda for whatever reason, you could have an SQS queue subscribed to your SNS topic and an EC2 instance draining this SQS queue, but this is much more complex and far away from a Serverless world.

So, my suggestion is:

  1. Create an API Gateway
  2. Connect it with an SNS Topic
  3. Create a Lambda function and subscribe it to the just created SNS Topic
  4. Send a request to your API Gateway (this will send a message to SNS, therefore triggering the subscribed Lambda function)
  5. Your Lambda function has now been invoked with the message from SNS. Grab the information that you need in order to send your SMS.

I suggest you take a look into Building an API Gateway API with AWS Integration and then learn how to Send SMS messages using Twillio's API, for example.

I also recommend you take a look into an SNS Event and into an API Gateway event so you know what to expect in your code.

Thales Minussi
  • 6,965
  • 1
  • 30
  • 48