#!/usr/bin/env python # coding: utf-8 # ### End to End demo of starting spot instance in AWS # In[54]: get_ipython().run_line_magic('reload_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') get_ipython().run_line_magic('matplotlib', 'inline') # In[55]: from aws_setup import * # ### Testing # In[56]: list(ec2.key_pairs.all()) # #### Define parameters # In[70]: vpc_name='fast-ai' instance_name = f'{vpc_name}-instance' instance_type = 't2.medium' # #### Get Existing VPC by tag name # In[71]: vpc = get_vpc(vpc_name); vpc # #### Request Spot instance # In[23]: spot_prices = get_spot_prices(); spot_prices[instance_type] # In[24]: launch_specs = LaunchSpecs(vpc, instance_type=instance_type, volume_size=80).build() # In[26]: launch_specs # In[27]: instance = create_spot_instance(instance_name, launch_specs, spot_price='0.5'); instance # Request on demand instance (if spot error) # In[ ]: # instance = create_instance(instance_name, vpc, instance_type='t2.micro'); instance # In[72]: instance = get_instance(instance_name); instance # In[73]: v1 = list(instance.volumes.all())[0] # In[79]: v1.detach_from_instance() # In[86]: v1.state # ### SSH # In[34]: client = connect_to_instance(instance) # #### Attach EBS volume (Optional) # In[68]: volume_tag = 'fast-ai-imagenet' # In[36]: _ = attach_volume(instance, volume_tag, device='/dev/xvdf') # In[42]: mount_volume(instance, device='/dev/xvdf', mount_dir='ebs_mount') # #### Mount EFS # In[48]: efs_addr = get_efs_address('fast-ai-efs'); efs_addr # In[46]: out, _ = run_command(client, 'mkdir ~/efs_mount_point') # In[49]: efs_mount_cmd = f'sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 {efs_addr}:/ ~/efs_mount_point' # In[50]: out, _ = run_command(client, efs_mount_cmd) # In[51]: out, _ = run_command(client, 'ls efs_mount_point') # no reformatting # In[ ]: