Issue
I am currently writing Python scripts and accessing data from an API. The data I get from this API is then saved on an AWS RDS SQL Server. I was wondering if there is a way to run these scripts on particular days without the need of having my computer on. Is there a remote server I can be running these for free? Or is this something I can use a Cron Job for (from my understanding Cron Jobs can only be run from my own machine). This data is being used for a class project website and so I need to be getting the latest data from the API on particular days automatically.
Solution
If you use AWS already, give AWS lambda a try. You can create a CRON trigger there (as well as many others).
It works like this:
- You provide a zip file which contains all necessary code. It will use one single function (which you can specify) as an entry point. It has to be either Python 2.7 or Python 3.6
- The zip file has to contain everything, including dependencies. Virtualenv is your friend to create that. Numpy is no problem
- Define the triggers (CRON, in your case)
- Define maximum resources (memory, execution time)
It's not free, but very cheap.
Gotchas:
- Lambda itself is stateless. Writing to a local file will not have any effect. Commonly you write to S3.
- Resource limits! At most it can execute 5min! Also the zip file size is limited.
- One execution is guaranteed, bit but not exaktly one
Answered By - Martin Thoma