如何自动启动,执行和停止EC2? [英] How to automatically start, execute and stop EC2?

查看:119
本文介绍了如何自动启动,执行和停止EC2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每天一次在GPU机器上测试我的Python库. 我决定使用AWS EC2进行测试. 但是,gpu机的费用很高,因此我想在测试结束后停止该实例.

I want to test my Python library in GPU machine once a day. I decided to use AWS EC2 for testing. However, the fee of gpu machine is very high, so I want to stop the instance after the test ends.

因此,我想每天自动执行一次以下操作

Thus, I want to do the followings once a day automatically

  1. 启动EC2实例(手动设置)
  2. 执行命令(测试->将日志推送到S3)
  3. 停止EC2(不可删除)

该怎么做?

推荐答案

这很简单...

在启动时运行脚本

要在实例启动时自动运行脚本(每次,而不是第一次启动),请将您的脚本放在以下目录中:

To run a script automatically when the instance starts (every time it starts, not just the first time), put your script in this directory:

/var/lib/cloud/scripts/per-boot/

测试完成后停止实例

只需在脚本末尾向操作系统发出关闭命令:

Simply issue a shutdown command to the operating system at the end of your script:

sudo shutdown now -h

这篇关于如何自动启动,执行和停止EC2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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