randomizer
randomizer

Reputation: 1

how to stop Amazon Aws EC2 instance?

I'm trying to write a script to stop several instances in our test environment on Friday and have them start back on Monday, to save little cost.

Is there a way to stop instances by IP addresses (and not by instance ID), or some other way I don't know about? (The reason being that instance ID's may change if an instance had to be deleted and recreated.)

Upvotes: 0

Views: 172

Answers (2)

BestPractices
BestPractices

Reputation: 12876

This is a zero code solution:

Put your instances into autoscale groups and add a shutdown and startup schedule on the autoscale group. This can be done in the AWS console.

This can also be automated using the AWS CLI.

Upvotes: 1

Mike Ryan
Mike Ryan

Reputation: 1438

Use EC2 Tags to give your instances key/value tag pairs, then write a script using Boto which searches for instances with the right tags, and then terminates them.

You could also use Boto to list instances matching the specific IP address, and terminate them that way.

But... IP addresses are dynamically assigned (unless you are using Elastic IPs). So why not make a note of the instance IDs when launching the instances, instead of the IP address?

Upvotes: 0

Related Questions