I am trying to create ec2 spot instances using boto3 api, so far I am able to get the spot instance history price, spin up a spot instance, etc.
But I don't know how to get the price we are paying for spot instance using boto api.
anyone know how to do this ?
Thanks
Update: See: Spot Instance Interruptions - Amazon Elastic Compute Cloud
Old answer:
When launching a spot instance under Amazon EC2, you specify a maximum hourly price, known as a bid. This is the maximum price that will be charged for the instance.
When the instance is launched, and on each hourly anniversary of the instance being in a running state, the instance will be charged at the then-current spot price.
If an instance is terminated due to the spot price rising above the bid price, then there is no charge for the partial hour where the instance was terminated. However, if the user terminates a spot instance, the partial hour will be charged.
Therefore, "the price we are paying for spot instance" is the price at the start of each hour. It is calculated at the time that the charge takes place.
To obtain the price charged for a spot instance, use the Spot Instance Data Feed that provides a data feed that describes your Spot Instance usage and pricing. This data feed is sent to an Amazon S3 bucket that you specify when you subscribe to the data feed. It is updated hourly.
Related
Spot Instance Definition:
Spot Instances are spare EC2 compute capacity in the AWS Cloud available to you at savings of up to 90% off compared to On-Demand prices
My Confusions are:
How this Spare EC2 compute capacity is calculated
This Spare Capacity calculation is based on the Current Account OR Current Region OR Entire AWS Regions ?
Anybody with an AWS Account can launch an Amazon EC2 instance as a Spot Instance. If there is available capacity for the selected Instance Type and Availability Zone, the Spot Instance will be launched and you will be charged a price that is at the current Spot Price (normally much less than On-Demand prices).
However, AWS can stop/terminate that Spot Instance at any time when they need the capacity for customers who are using On-Demand instances. Therefore, the Spot Instance is not guaranteed to keep running.
You have no visibility into the available capacity or the likelihood that the Spot Instance will be stopped/terminated. If you want to maintain a level of capacity using Spot Instances, then you can use a Spot Fleet - Amazon Elastic Compute Cloud, which can automatically replace Spot Instances when they are stopped/terminated.
I have an app that starts and stops an RDS instance on-demand. I understand how AWS charges for a stopped RDS instance.
Does AWS charge for startup/shutdown compute time?
The pricing documentation for RDS indicates:
Pricing is ... from the time a DB instance
is launched until it is stopped or deleted.
For RDS, more specifically:
RDS is billed in one-second increments for database instances and
attached storage. Pricing is still listed on a per-hour basis, but
bills are now calculated down to the second and show usage in decimal
form. There is a 10 minute minimum charge when an instance is created,
restored or started.
FYI, for regular EC2 instances:
Each time you start a stopped instance we charge a minimum of one
minute for usage. After one minute, we charge only for the seconds you
use.
The most cost efficient solution would be to use aurora serverless. This way you dont have to start and stop the instance.
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless.html
When you use Aurora Serverless, you pay for only the database resources that you consume, on a per-second basis.
As described in the title, I remember before in AWS spot market that if a spot instance is revoked in its first hour, all the charges would be refunded fully. Does this policy still work now?
If the EC2 service terminates or stops the spot instance in the first hour, then you are not charged.
To quote the Spot Instances FAQ:
If your Spot instance is terminated or stopped by Amazon EC2 in the
first instance hour, you will not be charged for that usage. However,
if you terminate the instance yourself, you will be charged to the
nearest second. If the Spot instance is terminated or stopped by
Amazon EC2 in any subsequent hour, you will be charged for your usage
to the nearest second. If you are running on Windows and you terminate
the instance yourself, you will be charged for an entire hour.
I am trying to launch a AWS spot instance for a duration. Before that I checked price history graph.
However, when I launch an instance, I get below message:
"minimum required Spot request fulfillment price of 0.477. "
Is spot instance price for fixed duration different from just spot instance?
How does prices for spot instance price for fixed duration are determined?
You are correct.
Introducing Amazon EC2 Spot Instances for Specific Duration Workloads says:
You can now request Amazon EC2 Spot instances to run continuously, for up to six hours, at a flat rate that saves you up to 50% compared to On-Demand prices.
The price will be higher than the normal Spot Instance price because there is a duration guarantee. A normal spot instance can be terminated at any time (with 2 minutes notice).
There is no information available about how the price is determined, but presumably it involves a prediction of having sufficient capacity over that time period possibly forcing normal spot instances to terminate in order to provide sufficient capacity for the defined duration.
A long time ago, there was the most useful spot price comparison graph that I have ever used, but it stopped working, as far as I know, because the creator ran out of time to maintain it. The website is still active ec2price.com and the code is on Github. Does anyone know if anyone has replicated this? or any way to do it myself? As I said it was really useful to decide which spot instance to choose.
You can see this information in the EC2 console by browsing to Spot Requests and selecting the Pricing History button.
If you want to select the cheapest ec2 instance type automatically you can create a spot fleet request; select all the instance types you might want to use and an allocation strategy of lowestPrice. Deploy this to a VPC with a subnet in all availability zones in your region to get the lowest price possible.
Besides codes, somebody must pay to maintain server that polling the information.
Check out How Spot Fleet Works. Spot fleet is way better than price monitoring. You can make request base on pricing for a fleet of instance type than limit yourself to specific instance type. You can kick start instances from a large fleet base on maximum instance price or vCPU price.
If you are using a SPOT ready batch application, after submit your bidding for fleet of different instance type and set the maximum per vCPU price, Spotfleet will automatically launch available instance with the best price. So you don't need to compete with limited popular instance(for example, c4.* SPOT instance is scarce for most region).
This is a win-win for both AWS and customer, as AWS able to spread the usage to underutilized instance type. IMHO, There is no point of keep raising the bid for particular type if those instance exhausted, while there is still many idle AWS instances in alternate zone that are not fully utilised for grab.