Spot instances are up to 90% cheaper than on-demand instances. However, AWS can interrupt them at any time to reclaim capacity for on-demand instances. An instance is notified of its upcoming interruption two minutes before it occurs.
Therefore, any job taking 2 minutes or less can never be interrupted by AWS and can always be safely run on spot instances.
Longer jobs should only be run on spot instances if it is acceptable for them to fail at any time due to instance interruption. This can be partially mitigated, while still maintaining most of the savings, by splitting the longer jobs into interruptible parts on spot instances and non-interruptible parts on on-demand instances.
Note that AWS doesn’t charge you for spot instances interrupted less than 1 hour after launch .
In order to use spot instances, your AWS account must have the AWSServiceRoleForEC2Spot
IAM service-linked role.
When you launch your first spot instance using the AWS Console automatically, it will automatically be created for you.
Alternatively, you can create it manually using the AWS CLI or the IAM console .
By default, a job uses an on-demand instance.
You can force it to use spot instances instead by appending spot=true
to the label.
A middle ground is using spot=auto
to attempt to launch as spot and automatically fall back to on-demand if no spot capacity is available:
runs-on: sprinters:aws:spot=auto