-
-
Save seeker815/252570bb479a58f2d650ee6162e6b11e to your computer and use it in GitHub Desktop.
Python - start stopped or stop running instances with particular tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
tagname = "Name" | |
tagvalue = "Value" | |
ec2 = boto3.resource('ec2') | |
ec2.instances.filter(Filters=[ | |
{'Name': 'tag': [tagname], 'Values': [tagvalue]}, | |
{'Name': 'instance-state-name', 'Values': ['running']} | |
]).start() | |
ec2.instances.filter(Filters=[ | |
{'Name': 'tag': [tagname], 'Values': [tagvalue]}, | |
{'Name': 'instance-state-name', 'Values': ['stopped']} | |
]).stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment