简体   繁体   中英

Run Python code on EC2 instance with Boto

The boto documentation explains how to launch an Amazon EC2 instance in python, but I cannot find an explanation of how to run a python script on the instance once it is launched. Is this possible with boto? Ultimately, I would like to run python on an EC2 instance in a way that allows me to interact with the python interpreter like I do on my own machine with IDLE and avoid having to paste code into PuTTY , eg I use RStudio-server for R on EC2.

IDLE doesn't have any way to run script remotely (although it used to), but there are a number of other ways to do it:

  • Many other IDEs, like PyCharm (not an endorsement, I just picked one at random), do have remote-interpreter features.
  • IPython is a souped-up interactive interpreter that can, among many other things, run remote interpreter instances in a single Qt or web notebook.
  • You can run a local X server (you're already doing so if you're not on Windows or Mac), tunnel SSH over X, and run IDLE on the EC2 instance with the GUI on your desktop.
  • Often you don't really need to run code remotely, just an easier way to "publish" your scripts to the EC2 and/or edit them remotely, so you can run them in PuTTY. Many IDEs and text editors have a way to do this, even those that don't do remote interpreters.

An Amazon EC2 instance is simply a server, so you can access to the server via ssh. Check this document http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html

Once you manage to login into the instance, you can install RStudio following this guide http://inundata.org/2011/03/30/r-ec2-rstudio-server/

About IDLE, I'm not sure if you can execute IDLE from the ec2 instance.

If i understand you correctly you want to run a piece of code on ec2 which you are triggering from boto. you might want to have a look at this tutorial . The only thing different for you would be your ami which would need all the necessary installations to run your script. Once you trigger it from boto , it will run on an ec2 instance of they type you mention and then close itself once the work is done. If you need the instances just for small amount of time you might want to look into spot instances too. Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM