title: aws cli- terminate spot instance every 15 minutes
body: <p>I have 6 spot instances for a project. I only need them up for 15 mins then I need to terminate them to spin then up again.</p>
  
  <p>My idea is as follow. Install aws cli within the AMI. Then create a cron job to terminate ec2 spot instance</p>
  
  <p>Current : <code>aws ec2 terminate-instances</code></p>
  
  <p>However you need the instance ID, being a spot instance I do not know the ID. </p>
  
  <p>--update--</p>
  
  <p>Per suggestion below, did stop-instance test. Got error</p>
  
  <p>aws ec2 stop-instances --instance-ids ec2metadata</p>
  
  <p>An error occurred (InvalidInstanceID.Malformed) when calling the StopInstances operation: Invalid id: "ec2metadata" (expecting "i-...")</p>
  
  <p>How can I terminate the instances within the instance I want to terminate?</p>