AWS | Twilio Send Text Message

This example demonstrates how to send SMS messages with the Twilio SDK and AWS lambda.

user  

Darren Holland

Clone This Example

Step #1 -
npm install serverless -g
Step #2 -
serverless install -u https://github.com/serverless/examples/tree/master/aws-node-twilio-send-text-message -n  aws-node-twilio-send-text-message

Send SMS Message with Twilio

This example demonstrates how to send SMS messages with the Twilio SDK and AWS lambda.

Live the live demo

Use Cases:

  • Sending users confirmation text messages

Setup

  1. Sign up for a Twilio account

  2. Create a new phone number in your Twilio trial account

  3. Grab your ACCOUNT SID and AUTH TOKEN from the Twilio console and plug those into the serverless.yml file in the next step

  4. Set your env variables in serverless.yml with your Twilio account values

    environment:
      # replace these env variables with your twilio account values
      TWILIO_ACCOUNT_SID: YOUR-TWILIO-ACCOUNT-SID-HERE
      TWILIO_AUTH_TOKEN: YOUR-TWILIO-AUTH-TOKEN-HERE
      TWILIO_PHONE_NUMBER: YOUR-TWILIO-PHONE-NUMBER-HERE

    If you want to use encrypted API keys, see our encrypted environment variables example

  5. Invoke the function and send an SMS message

    Update the to phone number the event.json file and message to send in the SMS

    Then invoke the function with the serverless CLI. Set the --path event.json so the function knows where to send the SMS.

    serverless invoke -f sendText --path event.json
  6. (Optional) Deploy the front-end application

    Update the API_ENDPOINT variable in the /frontend/index.html file and deploy the /frontend folder to a static host of your choice.

    We recommend S3, netlify, or surge.sh for quick and easy static site hosting.

Latest commit b2f54ec on Sep 24, 2017

New to serverless?

To get started, pop open your terminal & run:

npm install serverless -g