title: python - Mount EBS volume using boto3
body: <p>I want to use AWS Spot instances to train Neural Networks. To prevent loss of the model when the spot instance is terminated, I plan to create a snapshot of the EBS volume, make a new volume and attach it to a reserved instance. How can I mount, or make the EBS volume available using python &amp; boto3. </p>
  
  <p>These are the steps used to <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html" rel="nofollow">make the volume available</a> on Linux, but I want to automate the process so that I don't need to SSH into the instance every time. Here is the code I use to attach the volume - </p>
  
  <pre><code>import boto3
  ec2 = boto3.resource('ec2')
  
  spot = ec2.Instance('i-9a8f5082')
  res = ec2.Instance('i-86e65a13')
  
  snapshot = ec2.create_snapshot(VolumeId="vol-5315f7db", Description="testing spot instances")
  volume = ec2.create_volume(SnapshotId=snapshot.id, AvailabilityZone='us-west-2a')
  res.attach_volume(VolumeId="vol-5315f7db", Device='/dev/sdy')
  snapshot.delete()
  </code></pre>