如何在Amazone的EC2实例中运行代码? [英] How to run a code in an Amazone's EC2 instance?

查看:113
本文介绍了如何在Amazone的EC2实例中运行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对EC2的功能几乎一无所知。我创建了一个Amazon Web Service(AWS)帐户。然后,我启动了一个EC2实例。

I understand nearly nothing to the functioning of EC2. I created an Amazon Web Service (AWS) account. Then I launched an EC2 instance.

现在我想在此实例中执行Python代码,但我不知道该如何继续。是否有必要在实例中的某处加载代码?还是在Amazon的S3中将其链接到实例?

And now I would like to execute a Python code in this instance, and I don't know how to proceed. Is it necessary to load the code somewhere in the instance? Or in Amazon's S3 and to link it to the instance?

在哪里有指南解释可能的实例用法?在没有用户指南的情况下,我感觉就像是在飞碟的仪表板前一样。

Where is there a guide that explain the usages of instance that are possible? I feel like a man before a flying saucer's dashboard without user's guide.

推荐答案

这是一个非常简单的过程,可将Python脚本从在EC2实例本地运行。

Here's a very simple procedure to move your Python script from local to EC2 Instance and run it.

> 1. scp -i <filepath to Pem> <filepath to Py File> ec2-user@<Public DNS>.compute-1.amazonaws.com:<filepath in EC2 instance where you want
> your file to be>
> 2. Cd to to the directory in EC2 containing the file. Type Python <Filename.py> There it executed.

以下是一些喜欢逐步显示内容的人的具体示例:

Here's a concrete examples for those who likes things shown step-by-step:


  1. 在您的本地目录中,使用以下代码创建python脚本: print( Hello AWS)

  2. 假设您已经设置了AWS,并且想要在EC2中运行此脚本,则需要将文件SCP(安全复制协议)存储到EC2中的目录中。举个例子:





    -我的pem文件路径是〜/ Desktop / random.pem。

    -我的py文件的文件路径是〜/ Desktop / hello_aws.py

    -我的公共DNS是ec22-34-12-888

    -ec2我希望脚本存放在的目录位于/ home / ec2-user

    -因此,我在本地终端中运行的完整命令是:

      - My filepath to pem is ~/Desktop/random.pem.
      - My filepath to py file is ~/Desktop/hello_aws.py
      - My public DNS is ec22-34-12-888
      - The ec2 directory where I want my script to be is in /home/ec2-user
      - So the full command I run in my local terminal is:


      scp -i〜/ Desktop / random.pem〜/ Desktop / hello_aws.py ec2-user@ec2-34-201-49-170.compute-1.amazonaws.com :/ home / ec2-user

      scp -i ~/Desktop/random.pem ~/Desktop/hello_aws.py ec2-user@ec2-34-201-49-170.compute-1.amazonaws.com:/home/ec2-user




      1. 现在将ssh转到ec2实例cd到/ home / ec2-user(或您放置文件的任何位置)和Python hello_aws.py

      这篇关于如何在Amazone的EC2实例中运行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆