Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute a python script on Heroku?

I have a python script which I only need to run once (I don't want to have to commit it to the repo to send to the Cedar instance).

The Script aggregates data over my Django models and outputs a .csv file.

Normally in AWS, I would scp the script to the server, manage.py shell < script.py, and scp the produced .csv back to my machine.

I understand Heroku file systems are ephemeral, but is there a way to retrieve produced files on Heroku servers without uploading them to S3?

Here's my best shot:

cat script.py | heroku run manage.py shell --app appname

Works for a one line script, but not with line breaks.

Also, the above script will only produce command line output, not return a .csv file.

like image 218
grokpot Avatar asked Dec 09 '13 23:12

grokpot


People also ask

Can you use Python with Heroku?

Heroku runs your app in a dyno — a smart, secure container with your choice of Python version. Dynos come in different types, ranging from free dynos for getting started, to dynos at $7 per month for hobby projects, all the way to dedicated types for your highest-traffic apps.

How do I run a deployed app on Heroku?

To deploy your app to Heroku, use the git push command to push the code from your local repository's main branch to your heroku remote. For example: $ git push heroku main Initializing repository, done.


1 Answers

Heroku doesn't give you write permissions anywhere on your dyno (the only files it writes are the ones it checks out from your master branch when you push an update, and any dependencies). You'll have to upload your output to S3, save it to the log, or find some other delivery mechanism (email?)

like image 120
jraede Avatar answered Nov 14 '22 23:11

jraede