❗❗❗ 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 messages to AWS SQS without consideration of source.
- Python 3.8 (update
serverless.ymlif higher version is desired) - Pip
- Node.js and npm
- Serverless Framework
- AWS account
Clone this repo from GitHub, and navigate into the newly created directory to proceed.
Rename .env.default to .env and add values to VONAGE_API_KEY and VONAGE_API_SECRET provided by your Vonage API Dashboard.
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.
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/activateNext, 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-requirementsNow 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.txtShould you wish to run the app locally and test things out, before deploying to AWS Lambda, you can serve it with the following command:
sls wsgi serveBy default this will serve the app at http://localhost:5000. Hitting Ctrl+c will close it down.
With all the above finished successfully, you can now use Serverless to deploy the app to AWS Lambda.
sls deployIMPORTANT: This application does not contain any authentication for use. Therefore, ensure you add authentication in front of it to prevent public usage. By leaving it open to the public, it could result in usage charges at AWS and Vonage.
There are 4 URL endpoints available with this client:
1 HTTP GET request to /
- Doesn't perform any actions, but provides a quick way to test
2 HTTP POST request to /add
- This action stores the message in SQS.
- Submit a
POSTrequest with a JSON body like the following. Substitute the placeholders, indicated with<>with your data. - The result contains the SQS
MessageId.
{
"from": "<your_name_or_number>",
"message": "<sms_message_contents>",
"to": "<recipients_number>"
}3 HTTP GET request to /get
- Retrieves the message from SQS FIFO queue.
- Once received, the
ReceiptHandlecan be used to remove it from queue.
location=None, media_mode=relayed, archive_mode=manual
4 HTTP POST request to /delete
- This action deletes the message from SQS.
- Submit a
POSTrequest with a JSON body like the following. Substitute the placeholders, indicated with<>with your data.
{
"receipt_handle": "<your_receipt_handle>",
}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/get
The get endpoint will return a message for use.
GET https://7ulasfasdasdfw4.execute-api.us-east-1.amazonaws.com/dev/delete
The delete endpoint will delete a message from SQS.
To exit the virtualenv you can deactivate it, when desired.
deactivateNOTE: Depending on OS, you may need to prepend
virtualenvto the command above.
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.