Interacting between anvil website and AWS EC2 instance

Hi

I want to send a command from my Anvil website via uplink to an AWS EC2 instance to run some python code and return the output to the Anvil website
Does anyone know of a tutorial / example on the forum on how to do this or something similar? specifically:
How to setup uplink to initiate an AWS EC2 instance that will run every time the command is sent from my anvil website

I’m fairly sure that sort of thing has been discussed here before. Did you find anything with Search (top of page)?

@p.colbert There are a few topics that refer to connecting to an EC2 instance via uplink but there are no step-by-step examples/specific explanations:

It is clearly possible but I haven’t found any guides that “dumb it down”

I have been able to connect my Anvil app via uplink to my python local files but it requires I first run the script on my local machine (using wait forever). I don’t know how to do this on my EC2 instance, I don’t know how to keep a script running on an EC2 instance

Hi @woolfejeff ,

here is something to get you started. On your EC2 instance, create these scripts:

  1. activate (activates your python environment)
#!/bin/bash
. <my_python_enviroment>/bin/activate
  1. deploy (pulls your code from git)
#!/bin/bash
. activate
rm -rf <my_local_copy_dir>
git clone -b <my_branch> git@github.com:<my_git_name>/<my_repo_name>.git <my_local_copy_dir>
cd <my_local_copy_dir>
pip install -r requirements.txt
python setup.py install
  1. anvil_uplink_server (starts the script you already ran locally with ‘wait forever’)
#!/bin/bash
. activate
nohup python -m <my python uplink module name> &

To update your EC2 with the latest code from git:

. deploy

Then start your uplink server by:

. anvil_uplink_server

You should check out how to create a virtual python environment, and you probably need to make your scripts executable by using the chmod command.

Hope this helps.

Cheers,
Stein

2 Likes

Definitely a great start, Thanks!