0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS SDK for Ruby で Spot Request を送るときのそれっぽい値段を出す

Last updated at Posted at 2013-10-18

東京リージョンのVPC内に t1.micro のスポットリクエストを送るときに使う
それっぽい値段を出す

AZ片側だけで判定(ap-northeast-1a)
立ち上げるマシンはLinux

Ruby2.0.0-p247
aws-sdk 1.22.0

require "aws-sdk"

AWS.config(
  :access_key_id     => "access_key_id",
  :secret_access_key => "secret_access_key",
  :region            => "ap-northeast-1"
)

def soreppoi_price
  ec2 = AWS::EC2.new
  options = {
    :instance_types    => ["t1.micro"],
    :availability_zone => "ap-northeast-1a",
    :start_time        => (Time.now - 60 * 60 * 24).iso8601,
    :filters           => [
      {
        :name   => "product-description",
        :values => ["Linux/UNIX (Amazon VPC)"],
      }
    ],
  }
  resp = ec2.client.describe_spot_price_history(options)
  resp[:spot_price_history_set].each {|history|
    return history[:spot_price].to_f + 0.005
  }
end

puts soreppoi_price

参考にしたもの
http://itsneatlife.blogspot.jp/2013/08/aws-sdk-rubyspot-instancepricing-history.html
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client/V20131001.html#describe_spot_price_history-instance_method
http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSpotPriceHistory.html (Supported Filters)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?