/sendgrid-inbound-to-mongo

Small web server to send all messages from a Sendgrid inbound parse webhook to a MongoDB database

Primary LanguagePython

sendgrid-inbound-to-mongo

Small web server to send all messages from a Sendgrid inbound parse webhook to a MongoDB database

Installation:

Step 1 - Installing the Python components

  1. sudo apt update
  2. sudo apt install python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools

Step 2 - Installing MongoDB as a service

  1. wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
  2. echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
  3. sudo apt update
  4. sudo apt install mongodb-org
  5. sudo systemctl start mongod
  6. sudo systemctl enable mongod

Step 3 - Cloning the repository

  1. git clone https://github.com/jorivanee/sendgrid-inbound-to-mongo webhook && cd webhook

Step 4 - Setting up the Python Virtual Environment

  1. sudo apt install python3-venv
  2. python3 -m venv prod
  3. source prod/bin/activate

Step 5 - Setting up the Flask Application

  1. pip install -r requirements.txt
  2. deactivate
  3. cp config.example.json config.json
  4. sudo nano config.json

Step 6 - Setting up uWSGI

  1. sudo nano /etc/systemd/system/application.service
  2. Add the following lines:
[Unit]
Description=uWSGI instance to serve Webhook
After=network.target

[Service]
User=<your username>
Group=www-data
WorkingDirectory=/home/<your username>/webhook
Environment="PATH=/home/<your username>/webhook/prod/bin"
ExecStart=/home/<your username>/webhook/prod/bin/uwsgi --ini application.ini

[Install]
WantedBy=multi-user.target
  1. sudo systemctl start application
  2. sudo systemctl enable application

Step 7 - Setting up NGINX

  1. sudo apt install nginx
  2. sudo nano /etc/nginx/sites-available/webhook
  3. Add the following lines:
server {
    listen 80;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/<your username>/webhook/application.sock;
    }
}
  1. sudo ln /etc/nginx/sites-available/webhook /etc/nginx/sites-enabled/webhook
  2. sudo nginx -t If the above command gives an output saying the configuration test is successful, proceed
  3. sudo service nginx restart
  4. curl http://127.0.0.1 to verify if the installation worked