aws-sdk 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/lib/aws/api_config/AutoScaling-2011-01-01.yml +6 -2
  2. data/lib/aws/api_config/{EC2-2012-04-01.yml → EC2-2012-06-01.yml} +12 -0
  3. data/lib/aws/api_config/STS-2011-06-15.yml +0 -4
  4. data/lib/aws/auto_scaling/client.rb +6 -2
  5. data/lib/aws/auto_scaling/launch_configuration.rb +8 -0
  6. data/lib/aws/auto_scaling/launch_configuration_collection.rb +14 -4
  7. data/lib/aws/auto_scaling/scaling_policy.rb +17 -0
  8. data/lib/aws/auto_scaling/scaling_policy_options.rb +2 -0
  9. data/lib/aws/core.rb +13 -11
  10. data/lib/aws/core/cacheable.rb +1 -1
  11. data/lib/aws/core/client.rb +40 -39
  12. data/lib/aws/core/configuration.rb +24 -15
  13. data/lib/aws/core/credential_providers.rb +395 -0
  14. data/lib/aws/core/http/net_http_handler.rb +1 -0
  15. data/lib/aws/core/http/request.rb +4 -4
  16. data/lib/aws/core/log_formatter.rb +2 -0
  17. data/lib/aws/core/signature/version_2.rb +18 -5
  18. data/lib/aws/core/signature/version_3.rb +10 -10
  19. data/lib/aws/core/signature/version_4.rb +13 -13
  20. data/lib/aws/core/signer.rb +46 -0
  21. data/lib/aws/dynamo_db/batch_write.rb +2 -1
  22. data/lib/aws/dynamo_db/client.rb +9 -24
  23. data/lib/aws/dynamo_db/table.rb +0 -23
  24. data/lib/aws/ec2/client.rb +19 -1
  25. data/lib/aws/ec2/image.rb +4 -4
  26. data/lib/aws/ec2/instance.rb +17 -5
  27. data/lib/aws/ec2/instance_collection.rb +16 -1
  28. data/lib/aws/errors.rb +40 -0
  29. data/lib/aws/s3/client.rb +2 -1
  30. data/lib/aws/s3/presigned_post.rb +10 -8
  31. data/lib/aws/s3/request.rb +7 -5
  32. data/lib/aws/s3/s3_object.rb +10 -9
  33. data/lib/aws/simple_email_service.rb +1 -1
  34. data/lib/aws/simple_email_service/identity_collection.rb +1 -1
  35. data/lib/aws/sts.rb +2 -6
  36. data/lib/aws/sts/client.rb +14 -17
  37. metadata +7 -9
  38. data/lib/aws/api_config/EC2-2011-12-15.yml +0 -3638
  39. data/lib/aws/core/default_signer.rb +0 -67
  40. data/lib/aws/core/session_signer.rb +0 -90
  41. data/lib/aws/core/signature/version_3_http.rb +0 -72
@@ -106,6 +106,10 @@
106
106
  - :structure:
107
107
  Enabled:
108
108
  - :boolean
109
+ SpotPrice:
110
+ - :string
111
+ IamInstanceProfile:
112
+ - :string
109
113
  :outputs:
110
114
  :children:
111
115
  CreateLaunchConfigurationResult:
@@ -455,7 +459,7 @@
455
459
  member:
456
460
  :rename: :alarms
457
461
  :list: true
458
- MinAdjustmentMagnitude:
462
+ MinAdjustmentStep:
459
463
  :type: :integer
460
464
  - :name: DescribeScalingActivities
461
465
  :method: :describe_scaling_activities
@@ -647,7 +651,7 @@
647
651
  - :required
648
652
  Cooldown:
649
653
  - :integer
650
- MinAdjustmentMagnitude:
654
+ MinAdjustmentStep:
651
655
  - :integer
652
656
  :outputs:
653
657
  :children:
@@ -3260,6 +3260,12 @@
3260
3260
  DeleteOnTermination:
3261
3261
  - :boolean
3262
3262
  - :rename: networkInterfaces
3263
+ IamInstanceProfile:
3264
+ - :structure:
3265
+ Arn:
3266
+ - :string
3267
+ Name:
3268
+ - :string
3263
3269
  :outputs:
3264
3270
  :children:
3265
3271
  spotInstanceRequestSet:
@@ -3565,6 +3571,12 @@
3565
3571
  DeleteOnTermination:
3566
3572
  - :boolean
3567
3573
  - :rename: networkInterfaces
3574
+ IamInstanceProfile:
3575
+ - :structure:
3576
+ Arn:
3577
+ - :string
3578
+ Name:
3579
+ - :string
3568
3580
  :outputs:
3569
3581
  :children:
3570
3582
  groupSet:
@@ -39,10 +39,6 @@
39
39
  :inputs:
40
40
  DurationSeconds:
41
41
  - :integer
42
- SerialNumber:
43
- - :string
44
- TokenCode:
45
- - :string
46
42
  :outputs:
47
43
  :children:
48
44
  GetSessionTokenResult:
@@ -92,6 +92,8 @@ module AWS
92
92
  # * +:volume_size+ - (Integer)
93
93
  # * +:instance_monitoring+ - (Hash)
94
94
  # * +:enabled+ - (Boolean)
95
+ # * +:spot_price+ - (String)
96
+ # * +:iam_instance_profile+ - (String)
95
97
  #
96
98
  # === Response Structure:
97
99
  #
@@ -355,6 +357,8 @@ module AWS
355
357
  # * +:volume_size+ - (Integer)
356
358
  # * +:instance_monitoring+ - (Hash)
357
359
  # * +:enabled+ - (Boolean)
360
+ # * +:spot_price+ - (String)
361
+ # * +:iam_instance_profile+ - (String)
358
362
  # * +:created_time+ - (Time)
359
363
  # * +:next_token+ - (String)
360
364
  #
@@ -423,7 +427,7 @@ module AWS
423
427
  # * +:alarms+ - (Array<Hash>)
424
428
  # * +:alarm_name+ - (String)
425
429
  # * +:alarm_arn+ - (String)
426
- # * +:min_adjustment_magnitude+ - (Integer)
430
+ # * +:min_adjustment_step+ - (Integer)
427
431
  # * +:next_token+ - (String)
428
432
  #
429
433
  # @return [Core::Response]
@@ -608,7 +612,7 @@ module AWS
608
612
  # * +:scaling_adjustment+ - *required* - (Integer)
609
613
  # * +:adjustment_type+ - *required* - (String)
610
614
  # * +:cooldown+ - (Integer)
611
- # * +:min_adjustment_magnitude+ - (Integer)
615
+ # * +:min_adjustment_step+ - (Integer)
612
616
  #
613
617
  # === Response Structure:
614
618
  #
@@ -37,6 +37,10 @@ module AWS
37
37
  # @attr_reader [String,nil] user_data
38
38
  #
39
39
  # @attr_reader [Array<Hash>] block_device_mappings
40
+ #
41
+ # @attr_reader [String] iam_instance_profile
42
+ #
43
+ # @attr_reader [String] spot_price
40
44
  #
41
45
  class LaunchConfiguration < Core::Resource
42
46
 
@@ -71,6 +75,10 @@ module AWS
71
75
 
72
76
  attribute :ramdisk_id, :static => true
73
77
 
78
+ attribute :iam_instance_profile, :static => true
79
+
80
+ attribute :spot_price, :static => true
81
+
74
82
  attribute :user_data, :static => true do
75
83
  translates_output{|v| Base64.decode64(v) }
76
84
  end
@@ -57,6 +57,10 @@ module AWS
57
57
  #
58
58
  # @option options [String] :user_data The user data available to
59
59
  # the launched Amazon EC2 instances.
60
+ #
61
+ # @option options [String] :iam_instance_profile
62
+ #
63
+ # @option options [String] :spot_price
60
64
  #
61
65
  # @return [LaunchConfiguration]
62
66
  #
@@ -66,17 +70,23 @@ module AWS
66
70
  client_opts[:launch_configuration_name] = name
67
71
  client_opts[:image_id] = image_id_opt(image)
68
72
  client_opts[:instance_type] = instance_type
69
- client_opts[:block_device_mappings] = options[:block_device_mappings] if
70
- options.key?(:block_device_mappings)
71
73
  client_opts[:instance_monitoring] = instance_monitoring_opt(options) if
72
74
  options.key?(:detailed_instance_monitoring)
73
- client_opts[:kernel_id] = options[:kernel_id] if options[:kernel_id]
74
75
  client_opts[:key_name] = key_name_opt(options) if options[:key_pair]
75
- client_opts[:ramdisk_id] = options[:ramdisk_id] if options[:ramdisk_id]
76
76
  client_opts[:security_groups] = security_groups_opt(options) if
77
77
  options.key?(:security_groups)
78
78
  client_opts[:user_data] = user_data_opt(options) if options[:user_data]
79
79
 
80
+ [
81
+ :iam_instance_profile,
82
+ :spot_price,
83
+ :kernel_id,
84
+ :ramdisk_id,
85
+ :block_device_mappings,
86
+ ].each do |opt|
87
+ client_opts[opt] = options[opt] if options.key?(opt)
88
+ end
89
+
80
90
  client.create_launch_configuration(client_opts)
81
91
 
82
92
  LaunchConfiguration.new(name,
@@ -13,6 +13,21 @@
13
13
 
14
14
  module AWS
15
15
  class AutoScaling
16
+
17
+ #
18
+ # @attr_reader [String] arn
19
+ #
20
+ # @attr_reader [String] adjustment_type
21
+ #
22
+ # @attr_reader [Integer] scaling_adjustment
23
+ #
24
+ # @attr_reader [Hash] alarms Returns a hash of alarms names (keys)
25
+ # to alarm ARNs (values).
26
+ #
27
+ # @attr_reader [Integer] cooldown
28
+ #
29
+ # @attr_reader [Integer] min_adjustment_magnitude
30
+ #
16
31
  class ScalingPolicy < Core::Resource
17
32
 
18
33
  include ScalingPolicyOptions
@@ -48,6 +63,8 @@ module AWS
48
63
 
49
64
  attribute :cooldown
50
65
 
66
+ attribute :min_adjustment_magintude
67
+
51
68
  populates_from(:describe_policies) do |resp|
52
69
  resp.scaling_policies.find do |p|
53
70
  p.policy_name == name and
@@ -40,6 +40,8 @@ module AWS
40
40
  # after a scaling activity completes before any further
41
41
  # trigger-related scaling activities can start.
42
42
  #
43
+ # @option options [Integer] :min_adjustment_magnitude
44
+ #
43
45
  # @return [Hash]
44
46
  #
45
47
  def scaling_policy_options auto_scaling_group, policy_name, options
@@ -61,7 +61,7 @@ require 'aws/core/autoloader'
61
61
  module AWS
62
62
 
63
63
  # Current version of the AWS SDK for Ruby
64
- VERSION = "1.5.2"
64
+ VERSION = "1.5.3"
65
65
 
66
66
  register_autoloads(self) do
67
67
  autoload :Errors, 'errors'
@@ -75,8 +75,8 @@ module AWS
75
75
  autoload :Client, 'client'
76
76
  autoload :Collection, 'collection'
77
77
  autoload :Configuration, 'configuration'
78
+ autoload :CredentialProviders, 'credential_providers'
78
79
  autoload :Data, 'data'
79
- autoload :DefaultSigner, 'default_signer'
80
80
  autoload :IndifferentHash, 'indifferent_hash'
81
81
  autoload :Inflection, 'inflection'
82
82
  autoload :LazyErrorClasses, 'lazy_error_classes'
@@ -92,7 +92,7 @@ module AWS
92
92
  autoload :Response, 'response'
93
93
  autoload :ResponseCache, 'response_cache'
94
94
  autoload :ServiceInterface, 'service_interface'
95
- autoload :SessionSigner, 'session_signer'
95
+ autoload :Signer, 'signer'
96
96
  autoload :UriEscape, 'uri_escape'
97
97
  end
98
98
 
@@ -175,13 +175,13 @@ module AWS
175
175
  #
176
176
  # @param [Hash] options
177
177
  #
178
- # @option options [String] :access_key_id (nil) AWS access key id
178
+ # @option options [String] :access_key_id AWS access key id
179
179
  # credential.
180
180
  #
181
- # @option options [String] :secret_access_key (nil) AWS secret access
181
+ # @option options [String] :secret_access_key AWS secret access
182
182
  # key credential.
183
183
  #
184
- # @option options [String,nil] :session_token (nil) AWS secret token
184
+ # @option options [String,nil] :session_token AWS secret token
185
185
  # credential.
186
186
  #
187
187
  # @option options [String] :auto_scaling_endpoint ('autoscaling.us-east-1.amazonaws.com')
@@ -221,11 +221,11 @@ module AWS
221
221
  #
222
222
  # @option options [Object] :log_formatter The log formatter is responsible
223
223
  # for building log messages from responses. You can quickly change
224
- # log formats by providing a canned log formatter.
224
+ # log formats by providing a pre-configured log formatter.
225
225
  #
226
226
  # AWS.config(:log_formatter => AWS::Core::LogFormatter.colored)
227
227
  #
228
- # Here is the complete list of canned log formatters:
228
+ # Here is a list of pre-configured log formatters:
229
229
  #
230
230
  # * +AWS::Core::LogFormatter.default+
231
231
  # * +AWS::Core::LogFormatter.short+
@@ -298,8 +298,10 @@ module AWS
298
298
  # @option options [String] :simple_workflow_service ('swf.us-east-1.amazonaws.com')
299
299
  # The service endpoint for Amazon Simple Workflow Service.
300
300
  #
301
- # @option options [Object] :signer (AWS::DefaultSigner) The request signer. Defaults to
302
- # a default request signer implementation.
301
+ # @option options [Object] :credential_provider (AWS::Core::CredentialProviders::DefaultProvider.new)
302
+ # Returns the credential provider. The default credential provider
303
+ # attempts to check for statically assigned credentials, ENV credentials
304
+ # and credentials in the metadata service of EC2.
303
305
  #
304
306
  # @option options [String] :ssl_ca_file The path to a CA cert bundle in
305
307
  # PEM format.
@@ -320,7 +322,7 @@ module AWS
320
322
  # man-in-the-middle attacks and can pose a serious security
321
323
  # risk.
322
324
  #
323
- # @option options[Boolean] :stub_requests (false) When +true+ requests
325
+ # @option options [Boolean] :stub_requests (false) When +true+ requests
324
326
  # are not sent to AWS, instead empty reponses are generated and
325
327
  # returned to each service request.
326
328
  #
@@ -35,7 +35,7 @@ module AWS
35
35
  def cache_key
36
36
  @cache_key ||= begin
37
37
  endpoint_method = self.class.service_ruby_name + "_endpoint"
38
- config.signer.access_key_id + ":" +
38
+ config.credential_provider.access_key_id + ":" +
39
39
  config.send(endpoint_method) + ":" +
40
40
  self.class.name + ":" +
41
41
  local_cache_key
@@ -27,33 +27,12 @@ module AWS
27
27
  # @private
28
28
  CACHEABLE_REQUESTS = Set[]
29
29
 
30
- # Creates a new low-level client.
31
- #
32
- # == Required Options
33
- #
34
- # To create a client you must provide access to AWS credentials.
35
- # There are two options:
36
- #
37
- # * +:signer+ -- An object that responds to +access_key_id+
38
- # (to return the AWS Access Key ID) and to
39
- # <code>sign(string_to_sign)</code> (to return a signature
40
- # for a given string). An example implementation is
41
- # AWS::Core::DefaultSigner. This option is useful if you want to
42
- # more tightly control access to your secret access key (for
43
- # example by moving the signature computation into a
44
- # different process).
45
- #
46
- # * +:access_key_id+ and +:secret_access_key+ -- You can use
47
- # these options to provide the AWS Access Key ID and AWS
48
- # Secret Access Key directly to the client.
49
- #
50
- # == Optional
51
- #
52
- # * +:http_handler+ -- Any object that implements a
53
- # <code>handle(request, response)</code> method; an example
54
- # is BuiltinHttpHandler. This method is used to perform the
55
- # HTTP requests that this client constructs.
56
- #
30
+ # Creates a new low-level client.
31
+ # @param [Hash] options
32
+ # @option options [Core::Configuration] :config (AWS.config)
33
+ # The base configuration object to use. All other options
34
+ # are merged with this. Defaults to the AWS.config.
35
+ # @option (see AWS.config)
57
36
  def initialize options = {}
58
37
 
59
38
  options = options.dup # so we don't modify the options passed in
@@ -72,7 +51,7 @@ module AWS
72
51
  @config ||= AWS.config
73
52
  @config = @config.with(options)
74
53
 
75
- @signer = @config.signer
54
+ @credential_provider = @config.credential_provider
76
55
  @http_handler = @config.http_handler
77
56
  @endpoint = config.send(:"#{service_ruby_name}_endpoint")
78
57
  @port = config.send(:"#{service_ruby_name}_port")
@@ -82,11 +61,10 @@ module AWS
82
61
  # @return [Configuration] This clients configuration.
83
62
  attr_reader :config
84
63
 
85
- # @return [DefaultSigner,Object] Returns the signer for this client.
86
- # This is normally a DefaultSigner, but it can be configured to
87
- # an other object.
64
+ # @return [CredentialProviders::Provider] Returns the credentail
65
+ # provider for this client.
88
66
  # @private
89
- attr_reader :signer
67
+ attr_reader :credential_provider
90
68
 
91
69
  # @return [String] The snake-cased ruby name for the service
92
70
  # (e.g. 's3', 'iam', 'dynamo_db', etc).
@@ -113,7 +91,8 @@ module AWS
113
91
  #
114
92
  # s3_with_logging = s3.with_http_handler do |request, response|
115
93
  # $stderr.puts request.inspect
116
- # super
94
+ # super(request, response)
95
+ # $stderr.puts response.inspect
117
96
  # end
118
97
  #
119
98
  # The block executes in the context of an HttpHandler
@@ -132,8 +111,14 @@ module AWS
132
111
  with_options(:http_handler => handler)
133
112
  end
134
113
 
114
+ # Returns a new client with the passed configuration options
115
+ # merged with the current configuration options.
116
+ #
117
+ # no_retry_client = client.with_options(:max_retries => 0)
118
+ #
135
119
  # @param [Hash] options
136
- # @see AWS.config detailed list of accepted options.
120
+ # @option (see AWS.config)
121
+ # @return [Client]
137
122
  def with_options options
138
123
  with_config(config.with(options))
139
124
  end
@@ -141,6 +126,7 @@ module AWS
141
126
  # @param [Configuration] config The configuration object to use.
142
127
  # @return [Core::Client] Returns a new client object with the given
143
128
  # configuration.
129
+ # @private
144
130
  def with_config config
145
131
  self.class.new(:config => config)
146
132
  end
@@ -248,13 +234,18 @@ module AWS
248
234
  end
249
235
 
250
236
  def rebuild_http_request response
237
+ credential_provider.refresh if expired_credentials?(response)
251
238
  response.rebuild_request
252
239
  response.retry_count += 1
253
240
  end
254
241
 
255
242
  def sleep_durations response
256
- factor = scaling_factor(response)
257
- Array.new(config.max_retries) {|n| (2 ** n) * factor }
243
+ if expired_credentials?(response)
244
+ [0]
245
+ else
246
+ factor = scaling_factor(response)
247
+ Array.new(config.max_retries) {|n| (2 ** n) * factor }
248
+ end
258
249
  end
259
250
 
260
251
  def scaling_factor response
@@ -262,9 +253,18 @@ module AWS
262
253
  end
263
254
 
264
255
  def should_retry? response
256
+ expired_credentials?(response) or
265
257
  response.timeout? or
266
- response.throttled? or
267
- response.error.kind_of?(Errors::ServerError)
258
+ response.throttled? or
259
+ response.error.kind_of?(Errors::ServerError)
260
+ end
261
+
262
+ # @return [Boolean] Returns +true+ if the response contains an
263
+ # error message that indicates credentials have expired.
264
+ def expired_credentials? response
265
+ response.error and
266
+ response.error.respond_to?(:code) and
267
+ response.error.code == 'ExpiredTokenException'
268
268
  end
269
269
 
270
270
  def return_or_raise options, &block
@@ -428,6 +428,7 @@ module AWS
428
428
  opts.delete(:async)
429
429
 
430
430
  http_request = new_request
431
+ http_request.access_key_id = credential_provider.access_key_id
431
432
 
432
433
  # configure the http request
433
434
  http_request.service_ruby_name = service_ruby_name
@@ -443,7 +444,7 @@ module AWS
443
444
  send("configure_#{name}_request", http_request, opts, &block)
444
445
 
445
446
  http_request.headers["user-agent"] = user_agent_string
446
- http_request.add_authorization!(signer)
447
+ http_request.add_authorization!(credential_provider)
447
448
 
448
449
  http_request
449
450
 
@@ -156,8 +156,8 @@ module AWS
156
156
  # @attr_reader [String] simple_workflow_endpoint ('swf.us-east-1.amazonaws.com')
157
157
  # The service endpoint for Amazon Simple Workflow Service.
158
158
  #
159
- # @attr_reader [Object] signer
160
- # The request signer. Defaults to a default request signer implementation.
159
+ # @attr_reader [CredentialProvider::Provider] credential_provider
160
+ # Returns the object that is responsible for loading credentials.
161
161
  #
162
162
  # @attr_reader [String] ssl_ca_file The path to a CA cert bundle in
163
163
  # PEM format.
@@ -206,7 +206,14 @@ module AWS
206
206
  def initialize options = {}
207
207
 
208
208
  @created = options.delete(:__created__) || {}
209
-
209
+
210
+ # :signer is now a deprecated option, this ensures it will still
211
+ # work, but its now prefered to set :credential_provider instead.
212
+ # Credentail providers don't have to provide a #sign method.
213
+ if signer = options.delete(:signer)
214
+ options[:credential_provider] = signer
215
+ end
216
+
210
217
  options.each_pair do |opt_name, value|
211
218
  opt_name = opt_name.to_sym
212
219
  if self.class.accepted_options.include?(opt_name)
@@ -219,9 +226,11 @@ module AWS
219
226
  # @return [Hash] Returns a hash with your configured credentials.
220
227
  def credentials
221
228
  credentials = {}
222
- credentials[:access_key_id] = access_key_id
223
- credentials[:secret_access_key] = secret_access_key
224
- credentials[:session_token] = session_token if session_token
229
+ [:access_key_id, :secret_access_key, :session_token].each do |opt|
230
+ if value = credential_provider.send(opt)
231
+ credentials[opt] = value
232
+ end
233
+ end
225
234
  credentials
226
235
  end
227
236
 
@@ -371,7 +380,7 @@ module AWS
371
380
  end
372
381
 
373
382
  needs = [
374
- :signer,
383
+ :credential_provider,
375
384
  :http_handler,
376
385
  :"#{ruby_name}_endpoint",
377
386
  :"#{ruby_name}_port",
@@ -397,10 +406,10 @@ module AWS
397
406
 
398
407
  end
399
408
 
400
- add_option :access_key_id,
409
+ add_option :access_key_id,
401
410
  ENV['AWS_ACCESS_KEY_ID'] || ENV['AMAZON_ACCESS_KEY_ID']
402
411
 
403
- add_option :secret_access_key,
412
+ add_option :secret_access_key,
404
413
  ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY']
405
414
 
406
415
  add_option :session_token
@@ -417,13 +426,13 @@ module AWS
417
426
 
418
427
  add_option :proxy_uri do |config,uri| uri ? URI.parse(uri.to_s) : nil end
419
428
 
420
- add_option_with_needs :signer,
429
+ add_option_with_needs :credential_provider,
421
430
  [:access_key_id, :secret_access_key, :session_token] do |config|
422
-
423
- DefaultSigner.new(
424
- config.access_key_id,
425
- config.secret_access_key,
426
- config.session_token)
431
+
432
+ CredentialProviders::DefaultProvider.new(
433
+ :access_key_id => config.access_key_id,
434
+ :secret_access_key => config.secret_access_key,
435
+ :session_token => config.session_token)
427
436
 
428
437
  end
429
438