diff --git a/desktop_env/providers/aws/provider.py b/desktop_env/providers/aws/provider.py index 17f6bff..2f0c5cb 100644 --- a/desktop_env/providers/aws/provider.py +++ b/desktop_env/providers/aws/provider.py @@ -72,21 +72,34 @@ class AWSProvider(Provider): security_groups = [sg['GroupId'] for sg in instance['SecurityGroups']] subnet_id = instance['SubnetId'] instance_type = instance['InstanceType'] - iam_instance_profile = instance.get('IamInstanceProfile', {}).get('Arn', '') # Step 2: Launch a new instance from the snapshot logger.info(f"Launching a new instance from snapshot {snapshot_name}...") - new_instance = ec2_client.run_instances( - ImageId=snapshot_name, - InstanceType=instance_type, - SecurityGroupIds=security_groups, - SubnetId=subnet_id, - IamInstanceProfile={'Arn': iam_instance_profile} if iam_instance_profile else {}, - MinCount=1, - MaxCount=1 - ) + + run_instances_params = { + "MaxCount": 1, + "MinCount": 1, + "ImageId": snapshot_name, + "InstanceType": instance_type, + "EbsOptimized": True, + "NetworkInterfaces": [ + { + "SubnetId": subnet_id, + "AssociatePublicIpAddress": True, + "DeviceIndex": 0, + "Groups": security_groups + } + ] + } + + new_instance = ec2_client.run_instances(**run_instances_params) new_instance_id = new_instance['Instances'][0]['InstanceId'] logger.info(f"New instance {new_instance_id} launched from snapshot {snapshot_name}.") + logger.info(f"Waiting for instance {new_instance_id} to be running...") + ec2_client.get_waiter('instance_running').wait(InstanceIds=[new_instance_id]) + logger.info(f"Waiting for instance {new_instance_id} status checks to pass...") + ec2_client.get_waiter('instance_status_ok').wait(InstanceIds=[new_instance_id]) + logger.info(f"Instance {new_instance_id} is ready.") # Step 3: Terminate the old instance ec2_client.terminate_instances(InstanceIds=[path_to_vm])