This commit is contained in:
dzikafoczka 2024-12-20 21:36:52 +01:00
parent 14161fd8ef
commit 7e35161c5b

17
lb2.py
View File

@ -2,6 +2,7 @@ import boto3
import base64
from USER_DATA import user_data
import json
import time
# Configuration variables
PREFIX = "s464863"
@ -246,6 +247,22 @@ def create_ec2_instances(ec2_client, launch_template_id, subnet_id):
return instance_ids
def wait_for_instances_to_run(ec2_client, instance_ids):
print("Waiting for EC2 instances to be in 'running' state...")
while True:
# Get state of instances
response = ec2_client.describe_instances(InstanceIds=instance_ids)
states = [reservation['Instances'][0]['State']['Name'] for reservation in response['Reservations']]
# Check if all instances are running
if all(state == 'running' for state in states):
print("All EC2 instances are now 'running'.")
break
else:
print("Waiting for EC2 instances to reach 'running' state...")
time.sleep(10)
# Main function
def main():
# EC2 client