我在玩 EC2,这是我的场景:
一次:使用必要的密钥对创建一个 EC2 实例。
日常的 :
fire up an EC2 instance.
send a file of IDs to EC2 micro-instance from local machine.
fire a python script to process the IDs and generate an output file.
fetch the output file to the local machine from the EC2 instance.
stop the EC2 instance.
因素:
I am using the same EC2 instance every time I want to process this file.
I want to keep costs down, so I want to cron the whole process to start and stop at a certain time interval.
粗略的代码:
from boto.ec2.connection import EC2Connection
AWS_ACCESS_KEY_ID = 'yourkey'
AWS_SECRET_ACCESS_KEY = 'yoursecret'
conn = EC2Connection(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY)
reservation = conn.run_instances('ami-5647a33f', instance_type='m1.micro', key_name='mykey')
instance = reservation.instances[0]
while not instance.update() == 'running':
time.sleep(5)
## Fetch the file from local machine
## --> Do the processing here --<
## send the file back to the local machine
# time up for the day, stop it
instance.stop()
现在,我正在手动启动和停止 EC2 实例并来回同步文件。我想消除这一步。这是最好的方法还是你有什么建议?如果您可以使用来自本地计算机的示例输入文件 (abc.txt) 在代码中添加一些行,并在 ec2 中打印文件的内容并将其输出到 out.txt 并取回。没有密码提示的文件传输被证明是一个挑战。(最终将添加到 hosts 文件中,但尚未调查)
谢谢你们!