Browse files

Added support for the ClientToken request parameter to the RunInstanc…

…es API call.
  • Loading branch information...
1 parent 8d2f371 commit 15dc184ed60561dc83522358942d5a933b3af1bd Cody Robbins committed with Dec 1, 2010
Showing with 11 additions and 3 deletions.
  1. +2 −0 lib/AWS/EC2/instances.rb
  2. +9 −3 test/test_EC2_instances.rb
View
2 lib/AWS/EC2/instances.rb
@@ -23,6 +23,7 @@ class Base < AWS::Base
# @option options [optional, Boolean] :disable_api_termination (true) Specifies whether the instance can be terminated using the APIs. You must modify this attribute before you can terminate any "locked" instances from the APIs.
# @option options [optional, String] :instance_initiated_shutdown_behavior ('stop') Specifies whether the instance's Amazon EBS volumes are stopped or terminated when the instance is shut down. Valid values : 'stop', 'terminate'
# @option options [optional, Boolean] :base64_encoded (false)
+ # @option options [optional, String] :client_token (nil) Unique, case-sensitive identifier you provide to ensure idempotency of the request
#
def run_instances( options = {} )
options = { :image_id => "",
@@ -68,6 +69,7 @@ def run_instances( options = {} )
params["SubnetId"] = options[:subnet_id] unless options[:subnet_id].nil?
params["DisableApiTermination"] = options[:disable_api_termination].to_s unless options[:disable_api_termination].nil?
params["InstanceInitiatedShutdownBehavior"] = options[:instance_initiated_shutdown_behavior] unless options[:instance_initiated_shutdown_behavior].nil?
+ params["ClientToken"] = options[:client_token].to_s unless options[:client_token].nil?
return response_generator(:action => "RunInstances", :params => params)
end
View
12 test/test_EC2_instances.rb
@@ -38,6 +38,7 @@
<amiLaunchIndex>0</amiLaunchIndex>
<instanceType>m1.small</instanceType>
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
+ <clientToken>The client token</clientToken>
</item>
<item>
<instanceId>i-2bc64242</instanceId>
@@ -52,6 +53,7 @@
<amiLaunchIndex>1</amiLaunchIndex>
<instanceType>m1.small</instanceType>
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
+ <clientToken>The client token</clientToken>
</item>
<item>
<instanceId>i-2be64332</instanceId>
@@ -66,6 +68,7 @@
<amiLaunchIndex>2</amiLaunchIndex>
<instanceType>m1.small</instanceType>
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
+ <clientToken>The client token</clientToken>
</item>
</instancesSet>
</RunInstancesResponse>
@@ -242,12 +245,12 @@
specify "should be able to be run" do
- @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1').
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "ClientToken" => 'The client token').
returns stub(:body => @run_instances_response_body, :is_a? => true)
- @ec2.run_instances( :image_id => "ami-60a54009" ).should.be.an.instance_of Hash
+ @ec2.run_instances( :image_id => "ami-60a54009", :client_token => 'The client token' ).should.be.an.instance_of Hash
- response = @ec2.run_instances( :image_id => "ami-60a54009" )
+ response = @ec2.run_instances( :image_id => "ami-60a54009", :client_token => 'The client token' )
response.reservationId.should.equal "r-47a5402e"
response.ownerId.should.equal "495219933132"
@@ -263,6 +266,7 @@
response.instancesSet.item[0].keyName.should.equal "example-key-name"
response.instancesSet.item[0].instanceType.should.equal "m1.small"
response.instancesSet.item[0].launchTime.should.equal "2007-08-07T11:51:50.000Z"
+ response.instancesSet.item[0].clientToken.should.equal "The client token"
response.instancesSet.item[1].instanceId.should.equal "i-2bc64242"
response.instancesSet.item[1].imageId.should.equal "ami-60a54009"
@@ -273,6 +277,7 @@
response.instancesSet.item[1].keyName.should.equal "example-key-name"
response.instancesSet.item[1].instanceType.should.equal "m1.small"
response.instancesSet.item[1].launchTime.should.equal "2007-08-07T11:51:50.000Z"
+ response.instancesSet.item[1].clientToken.should.equal "The client token"
response.instancesSet.item[2].instanceId.should.equal "i-2be64332"
response.instancesSet.item[2].imageId.should.equal "ami-60a54009"
@@ -283,6 +288,7 @@
response.instancesSet.item[2].keyName.should.equal "example-key-name"
response.instancesSet.item[2].instanceType.should.equal "m1.small"
response.instancesSet.item[2].launchTime.should.equal "2007-08-07T11:51:50.000Z"
+ response.instancesSet.item[2].clientToken.should.equal "The client token"
end

0 comments on commit 15dc184

Please sign in to comment.