-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.py
executable file
·36 lines (27 loc) · 882 Bytes
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import boto3
STACK_NAME = "ec2-gaming-sunshine"
def main():
client = boto3.client("ec2")
ec2 = boto3.resource("ec2")
response = client.describe_instances(
Filters=[
{"Name": "tag:Name", "Values": [f"{STACK_NAME}-instance"]},
{"Name": "instance-state-name", "Values": ["stopped"]},
]
)
reservations = response["Reservations"]
if len(reservations) == 0:
print("No stopped instances found, aborting.")
return
instances = reservations[0]["Instances"]
if len(instances) > 1:
print("More than one instance found, aborting.")
return
instance_id = instances[0]["InstanceId"]
ec2_instance = ec2.Instance(instance_id)
print(f"Starting {instance_id}")
response = ec2_instance.start()
print(response)
if __name__ == "__main__":
main()