Best Flask open-source libraries and packages

Sms aws sqs python sender

Python Flask AWS Lambda function to store sms messages to AWS SQS for sending, and added route to send.
Updated 7 months ago

sms-aws-sqs-python-sender

❗❗❗ This repo is now deprecated. Check the Vonage Developer Blog for more blog posts and tutorials. For more sample Vonage projects, check the Vonage Community GitHub repo.

Python function to store bulk sms messages to AWS SQS for 1 per second sending.

Prerequisites

Setup Instructions

Clone this repo from GitHub, and navigate into the newly created directory to proceed.

Environment

Rename .env.default to .env and add values to VONAGE_API_KEY and VONAGE_API_SECRET provided by your Vonage Video APIs account.

AWS Setup

You will need to create AWS credentials as indicated by Serverless. Update the .env file with these.

Also, create a new SQS FIFO queue using the default settings, and update .env with the SQS queue URL. By using FIFO, it ensures messages are sent in the order they were stored.

Usage

To start, create a virtualenv from within the project root to contain the project as you proceed. Then activate it as follows:

virtualenv venv --python=python3
source venv/bin/activate

Next, initialize npm and follow the prompts selecting the defaults. Unless you desire to change any of them. Also, use npm to install needed dependencies for dev to enable Serverless and Lambda to work with the Flask app.

npm init
npm install --save-dev serverless-wsgi serverless-python-requirements

Now you can use pip to install the required Python dependencies. The dependencies are already listed in the requirements.txt, so instruct pip to use it.

pip install -r requirements.txt

Running Local

You can run the app locally and test things out, prior to deploying to AWS Lambda, you can serve it with the following command:

sls wsgi serve

By default this will serve the app at http://localhost:5000. Hitting Ctrl+c will close it down.

Deploy to Lambda

With all the above finished successfully, you can now use Serverless to deploy the app to AWS Lambda.

sls deploy

Available Endpoints

There are 4 URL endpoints available with this client:

  • GET request to /

    • Doesn't perform any actions, but provides a quick way to test
  • POST request to /add

    • This will store the message in SQS.
    • Pass a POST with a JSON body like the following. Substitute the placeholders, indicated with <> with your data.
    • The result will be contain the SQS MessageId.
{
    "from": "<your_name_or_number>",
    "message": "<sms_message_contents>",
    "to": "<recipients_number>"
}
  • GET request to /process
    • Kicks off the sending process.
    • Retrieves the message from SQS FIFO queue.
    • Connects to Nexmo, and sends the SMS message.
location=None, media_mode=relayed, archive_mode=manual
Examples:

Go to the URL provided by the deploy process. Below are some examples of what sample requests may look like: (Your URL will vary.)

GET https://7ulasfasdasdfw4.execute-api.us-east-1.amazonaws.com/dev/

The / endpoint returns the generic message.

POST https://7ulasfasdasdfw4.execute-api.us-east-1.amazonaws.com/dev/add

The add endpoint will return the SQS MessageId.

GET https://7ulasfasdasdfw4.execute-api.us-east-1.amazonaws.com/dev/process

The process endpoing will return a message indicating a successful send.

Deactivating Virtualenv

To exit the virtualenv you can deactivate it, when desired.

deactivate

NOTE: Depending on OS, you may need to prepend virtualenv to the command above.

Contributing

We love questions, comments, issues - and especially pull requests. Either open an issue to talk to us, or reach us on twitter: https://twitter.com/VonageDev.