-1

I want to schedule a (AWS) linux machine to start, run a program, and then shut itself down (to keep costs at a minimum). I can put

mycommand; shutdown

in the /etc/rc.local file. But then I can't get into the machine if I ever need to make a change. Do I create another instance and attach the first machine's EBS storage whenever I need to change it? Or is there a better way to handle this?

2 Answers2

-1

I this situation i would add a Tag to the ec2 instance. Then either modify "mycommand", or create another script that can call "mycommand". Then you can perform a check to see if the tag exists / what value it is and act accordingly.

Theres a nice gist (its actually a userdata script for an instance) that shows the steps of installing the AWS CLI, and how to use bash to get the tags: https://gist.github.com/codeinthehole/ab9a8dc30917c5705846

MisterSmith
  • 2,884
  • 1
  • 10
  • 13
  • What I described above can be done - it's what I was doing when I asked the question. An EC2 instance does not have to be running to detach/attach even its root volume. Indeed, it would be very disappointing if you couldn't recover volumes this way. But it's certainly cumbersome. – BuffaloSpeedway Apr 10 '18 at 19:10
-1

Yes, you should be using an ebs-backed root device on your instance.

Then, if you want to modify the way your instance work, you can attach the EBS on a running instance, mount the filesystem, modify it for your needs, umount, detach and restart your instance.

smaftoul
  • 2,375
  • 17
  • 14