问题
I want to run data analysis using AWS that'll probably take a few days. I've setup a system where spot instances will reload the same EBS volume so it can resume the analysis after a termination. So far I've got it working where I can just generate a persistent spot request and have the analysis keep running and continue after spot instance terminations until it is done.
But I also want the spot instance to cancel the persistent spot instance request when the analysis is finished. Is there anyway to get the request ID from within the spot instance?
回答1:
The spot instance information is not available from the EC2 metadata. However, the instance ID is.
- Get the Instance ID from the EC2 metadata.
- Use DescribeInstances (or
ec2-describe-instances
, oraws ec2 describe-instances
to get the instance information for the instance. - Within the instance information is
spotInstanceRequestId
which is the spot instance request ID you're looking for.
来源:https://stackoverflow.com/questions/24289785/aws-cancel-spot-instance-request-within-a-spot-instace