aws-sdk 1.32.0 → 1.50.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -10
  3. data/bin/aws-rb +11 -1
  4. data/endpoints.json +191 -26
  5. data/lib/aws/api_config/AutoScaling-2011-01-01.yml +201 -0
  6. data/lib/aws/api_config/CloudFormation-2010-05-15.yml +15 -1
  7. data/lib/aws/api_config/CloudFront-2013-11-22.yml +2918 -0
  8. data/lib/aws/api_config/CloudFront-2014-01-31.yml +2934 -0
  9. data/lib/aws/api_config/CloudFront-2014-05-31.yml +3100 -0
  10. data/lib/aws/api_config/CloudSearch-2013-01-01.yml +1164 -0
  11. data/lib/aws/api_config/CloudTrail-2013-11-01.yml +4 -33
  12. data/lib/aws/api_config/DynamoDB-2012-08-10.yml +101 -1
  13. data/lib/aws/api_config/EC2-2013-08-15.yml +2 -2
  14. data/lib/aws/api_config/EC2-2013-10-01.yml +2 -2
  15. data/lib/aws/api_config/EC2-2013-10-15.yml +3 -78
  16. data/lib/aws/api_config/EC2-2014-02-01.yml +4755 -0
  17. data/lib/aws/api_config/EC2-2014-05-01.yml +4812 -0
  18. data/lib/aws/api_config/ELB-2012-06-01.yml +65 -1
  19. data/lib/aws/api_config/EMR-2009-03-31.yml +20 -1
  20. data/lib/aws/api_config/ElastiCache-2014-03-24.yml +1375 -0
  21. data/lib/aws/api_config/ElastiCache-2014-07-15.yml +1385 -0
  22. data/lib/aws/api_config/ElasticBeanstalk-2010-12-01.yml +8 -1
  23. data/lib/aws/api_config/ElasticTranscoder-2012-09-25.yml +798 -1
  24. data/lib/aws/api_config/IAM-2010-05-08.yml +44 -2
  25. data/lib/aws/api_config/Kinesis-2013-12-02.yml +1 -1
  26. data/lib/aws/api_config/OpsWorks-2013-02-18.yml +201 -1
  27. data/lib/aws/api_config/RDS-2013-09-09.yml +1 -2
  28. data/lib/aws/api_config/Redshift-2012-12-01.yml +25 -1
  29. data/lib/aws/api_config/Route53-2013-04-01.yml +889 -0
  30. data/lib/aws/api_config/SNS-2010-03-31.yml +16 -1
  31. data/lib/aws/api_config/SQS-2012-11-05.yml +86 -1
  32. data/lib/aws/api_config/STS-2011-06-15.yml +5 -1
  33. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +1 -1
  34. data/lib/aws/api_config/Support-2013-04-15.yml +63 -0
  35. data/lib/aws/auto_scaling/group.rb +1 -1
  36. data/lib/aws/cloud_formation/stack_resource_collection.rb +1 -1
  37. data/lib/aws/cloud_front/client.rb +13 -1
  38. data/lib/aws/cloud_search/client.rb +6 -2
  39. data/lib/aws/cloud_watch/alarm.rb +3 -0
  40. data/lib/aws/core.rb +16 -1
  41. data/lib/aws/core/client.rb +10 -1
  42. data/lib/aws/core/configuration.rb +3 -2
  43. data/lib/aws/core/credential_providers.rb +130 -12
  44. data/lib/aws/core/http/connection_pool.rb +23 -3
  45. data/lib/aws/core/http/net_http_handler.rb +18 -21
  46. data/lib/aws/core/http/request.rb +10 -0
  47. data/lib/aws/core/ini_parser.rb +42 -0
  48. data/lib/aws/core/lazy_error_classes.rb +20 -2
  49. data/lib/aws/core/log_formatter.rb +1 -1
  50. data/lib/aws/core/model.rb +5 -0
  51. data/lib/aws/core/option_grammar.rb +9 -9
  52. data/lib/aws/core/policy.rb +2 -3
  53. data/lib/aws/core/response.rb +4 -0
  54. data/lib/aws/core/signers/version_4.rb +1 -1
  55. data/lib/aws/core/signers/version_4/chunk_signed_stream.rb +1 -1
  56. data/lib/aws/core/xml/frame.rb +1 -0
  57. data/lib/aws/core/xml/grammar.rb +1 -0
  58. data/lib/aws/dynamo_db.rb +16 -0
  59. data/lib/aws/dynamo_db/batch_write.rb +2 -0
  60. data/lib/aws/dynamo_db/table.rb +4 -8
  61. data/lib/aws/ec2.rb +1 -1
  62. data/lib/aws/ec2/client.rb +64 -1
  63. data/lib/aws/ec2/image_collection.rb +1 -2
  64. data/lib/aws/ec2/instance.rb +3 -3
  65. data/lib/aws/ec2/instance_collection.rb +14 -3
  66. data/lib/aws/ec2/snapshot_collection.rb +1 -1
  67. data/lib/aws/ec2/subnet_collection.rb +7 -3
  68. data/lib/aws/ec2/tagged_collection.rb +14 -0
  69. data/lib/aws/ec2/volume_collection.rb +4 -0
  70. data/lib/aws/ec2/vpc.rb +8 -0
  71. data/lib/aws/ec2/vpc_collection.rb +1 -1
  72. data/lib/aws/elasticache/client.rb +8 -2
  73. data/lib/aws/emr/job_flow_collection.rb +4 -6
  74. data/lib/aws/glacier.rb +4 -4
  75. data/lib/aws/glacier/vault.rb +1 -1
  76. data/lib/aws/iam/server_certificate.rb +24 -17
  77. data/lib/aws/iam/signing_certificate.rb +13 -1
  78. data/lib/aws/rails.rb +1 -1
  79. data/lib/aws/rds/db_instance.rb +5 -6
  80. data/lib/aws/record/abstract_base.rb +0 -1
  81. data/lib/aws/record/hash_model.rb +1 -1
  82. data/lib/aws/record/model.rb +1 -1
  83. data/lib/aws/route_53/client.rb +5 -2
  84. data/lib/aws/route_53/hosted_zone.rb +39 -16
  85. data/lib/aws/route_53/hosted_zone_collection.rb +2 -1
  86. data/lib/aws/s3/bucket_lifecycle_configuration.rb +22 -6
  87. data/lib/aws/s3/cipher_io.rb +1 -1
  88. data/lib/aws/s3/client.rb +155 -7
  89. data/lib/aws/s3/client/xml.rb +7 -0
  90. data/lib/aws/s3/multipart_upload.rb +3 -1
  91. data/lib/aws/s3/object_collection.rb +1 -1
  92. data/lib/aws/s3/presign_v4.rb +13 -4
  93. data/lib/aws/s3/s3_object.rb +3 -0
  94. data/lib/aws/simple_email_service.rb +13 -0
  95. data/lib/aws/simple_email_service/identity.rb +21 -0
  96. data/lib/aws/simple_workflow/decision_task.rb +2 -2
  97. data/lib/aws/simple_workflow/decision_task_collection.rb +0 -2
  98. data/lib/aws/simple_workflow/option_formatters.rb +1 -1
  99. data/lib/aws/simple_workflow/workflow_execution_collection.rb +2 -2
  100. data/lib/aws/simple_workflow/workflow_type.rb +0 -2
  101. data/lib/aws/sns/message.rb +11 -1
  102. data/lib/aws/sns/topic.rb +1 -1
  103. data/lib/aws/sns/topic_collection.rb +1 -1
  104. data/lib/aws/sqs/queue.rb +26 -14
  105. data/lib/aws/sqs/queue_collection.rb +4 -0
  106. data/lib/aws/sqs/received_message.rb +4 -0
  107. data/lib/aws/sts/client.rb +9 -0
  108. data/lib/aws/version.rb +1 -1
  109. metadata +113 -117
@@ -116,7 +116,8 @@ module AWS
116
116
  #
117
117
  # @attr_reader [Logger,nil] logger (nil) The logging interface.
118
118
  #
119
- # @attr_reader [Symbol] log_level (:info) The log level.
119
+ # @attr_reader [Symbol] log_level (:info) The log level to use when
120
+ # logging every API call. Does not set the `:logger`'s log_level.
120
121
  #
121
122
  # @attr_reader [LogFormatter] log_formatter The log message formatter.
122
123
  #
@@ -483,7 +484,7 @@ module AWS
483
484
  add_option :session_token
484
485
 
485
486
  add_option :region do |cfg,region|
486
- region || ENV['AWS_REGION'] || ENV['AMAZON_REGION'] || 'us-east-1'
487
+ region || ENV['AWS_REGION'] || ENV['AMAZON_REGION'] || ENV['AWS_DEFAULT_REGION'] || 'us-east-1'
487
488
  end
488
489
 
489
490
  add_option_with_needs :credential_provider,
@@ -16,6 +16,7 @@ require 'net/http'
16
16
  require 'timeout'
17
17
  require 'thread'
18
18
  require 'time'
19
+ require 'json'
19
20
 
20
21
  module AWS
21
22
  module Core
@@ -37,14 +38,22 @@ module AWS
37
38
  # `:access_key_id` or the `:secret_access_key` can not be found.
38
39
  #
39
40
  def credentials
40
- @cached_credentials ||= begin
41
- creds = get_credentials
42
- unless creds[:access_key_id] and creds[:secret_access_key]
43
- raise Errors::MissingCredentialsError
41
+ raise Errors::MissingCredentialsError unless set?
42
+ @cached_credentials.dup
43
+ end
44
+
45
+ # @return [Boolean] Returns true if has credentials and it contains
46
+ # at least the `:access_key_id` and `:secret_access_key`.
47
+ #
48
+ def set?
49
+ @cache_mutex ||= Mutex.new
50
+ unless @cached_credentials
51
+ @cache_mutex.synchronize do
52
+ @cached_credentials ||= get_credentials
44
53
  end
45
- creds
46
54
  end
47
- @cached_credentials.dup
55
+ !!(@cached_credentials[:access_key_id] &&
56
+ @cached_credentials[:secret_access_key])
48
57
  end
49
58
 
50
59
  # @return [String] Returns the AWS access key id.
@@ -108,7 +117,9 @@ module AWS
108
117
  @providers = []
109
118
  @providers << StaticProvider.new(static_credentials)
110
119
  @providers << ENVProvider.new('AWS')
120
+ @providers << ENVProvider.new('AWS', :access_key_id => 'ACCESS_KEY', :secret_access_key => 'SECRET_KEY', :session_token => 'SESSION_TOKEN')
111
121
  @providers << ENVProvider.new('AMAZON')
122
+ @providers << SharedCredentialFileProvider.new if Dir.home rescue ArgumentError
112
123
  @providers << EC2Provider.new
113
124
  end
114
125
 
@@ -117,14 +128,17 @@ module AWS
117
128
 
118
129
  def credentials
119
130
  providers.each do |provider|
120
- begin
131
+ if provider.set?
121
132
  return provider.credentials
122
- rescue Errors::MissingCredentialsError
123
133
  end
124
134
  end
125
135
  raise Errors::MissingCredentialsError
126
136
  end
127
137
 
138
+ def set?
139
+ providers.any?(&:set?)
140
+ end
141
+
128
142
  def refresh
129
143
  providers.each do |provider|
130
144
  provider.refresh
@@ -181,8 +195,9 @@ module AWS
181
195
  include Provider
182
196
 
183
197
  # @param [String] prefix The prefix to apply to the ENV variable.
184
- def initialize prefix
198
+ def initialize(prefix, suffixes=Hash[KEYS.map{|key| [key, key.to_s.upcase]}])
185
199
  @prefix = prefix
200
+ @suffixes = suffixes
186
201
  end
187
202
 
188
203
  # @return [String]
@@ -192,7 +207,7 @@ module AWS
192
207
  def get_credentials
193
208
  credentials = {}
194
209
  KEYS.each do |key|
195
- if value = ENV["#{@prefix}_#{key.to_s.upcase}"]
210
+ if value = ENV["#{@prefix}_#{@suffixes[key]}"]
196
211
  credentials[key] = value
197
212
  end
198
213
  end
@@ -223,7 +238,7 @@ module AWS
223
238
 
224
239
  attr_reader :credential_file
225
240
 
226
- # @param [Sring] credential_file The file path of a credential file
241
+ # @param [String] credential_file The file path of a credential file
227
242
  def initialize(credential_file)
228
243
  @credential_file = credential_file
229
244
  end
@@ -246,6 +261,58 @@ module AWS
246
261
  end
247
262
  end
248
263
 
264
+ class SharedCredentialFileProvider
265
+
266
+ include Provider
267
+
268
+ # @api private
269
+ KEY_MAP = {
270
+ "aws_access_key_id" => :access_key_id,
271
+ "aws_secret_access_key" => :secret_access_key,
272
+ "aws_session_token" => :session_token,
273
+ }
274
+
275
+ # @option [String] :path
276
+ # @option [String] :profile_name
277
+ def initialize(options = {})
278
+ @path = options[:path] || File.join(Dir.home, '.aws', 'credentials')
279
+ @profile_name = options[:profile_name]
280
+ @profile_name ||= ENV['AWS_PROFILE']
281
+ @profile_name ||= 'default'
282
+ end
283
+
284
+ # @return [String]
285
+ attr_reader :path
286
+
287
+ # @return [String]
288
+ attr_reader :profile_name
289
+
290
+ # (see Provider#get_credentials)
291
+ def get_credentials
292
+ if File.exist?(path) && File.readable?(path)
293
+ load_from_path
294
+ else
295
+ {}
296
+ end
297
+ end
298
+
299
+ private
300
+
301
+ def load_from_path
302
+ profile = load_profile
303
+ KEY_MAP.inject({}) do |credentials, (source, target)|
304
+ credentials[target] = profile[source] if profile.key?(source)
305
+ credentials
306
+ end
307
+ end
308
+
309
+ def load_profile
310
+ ini = IniParser.parse(File.read(path))
311
+ ini[profile_name] || {}
312
+ end
313
+
314
+ end
315
+
249
316
  # This credential provider tries to get credentials from the EC2
250
317
  # metadata service.
251
318
  class EC2Provider
@@ -313,7 +380,7 @@ module AWS
313
380
  # `:access_key_id` or the `:secret_access_key` can not be found.
314
381
  #
315
382
  def credentials
316
- if @credentials_expiration && @credentials_expiration.utc <= Time.now.utc - 5 * 60
383
+ if @credentials_expiration && @credentials_expiration.utc <= (Time.now.utc + (15 * 60))
317
384
  refresh
318
385
  end
319
386
  super
@@ -465,6 +532,57 @@ module AWS
465
532
 
466
533
  end
467
534
 
535
+ # An auto-refreshing credential provider that works by assuming
536
+ # a role via {AWS::STS#assume_role}.
537
+ #
538
+ # provider = AWS::Core::CredentialProviders::AssumeRoleProvider.new(
539
+ # sts: AWS::STS.new(access_key_id:'AKID', secret_access_key:'SECRET'),
540
+ # # assume role options:
541
+ # role_arn: "linked::account::arn",
542
+ # role_session_name: "session-name"
543
+ # )
544
+ #
545
+ # ec2 = AWS::EC2.new(credential_provider:provider)
546
+ #
547
+ # If you omit the `:sts` option, a new {STS} service object will be
548
+ # constructed and it will use the default credential provider
549
+ # from {Aws.config}.
550
+ #
551
+ class AssumeRoleProvider
552
+
553
+ include Provider
554
+
555
+ # @option options [AWS::STS] :sts (STS.new) An instance of {AWS::STS}.
556
+ # This is used to make the API call to assume role.
557
+ # @option options [required, String] :role_arn
558
+ # @option options [required, String] :role_session_name
559
+ # @option options [String] :policy
560
+ # @option options [Integer] :duration_seconds
561
+ # @option options [String] :external_id
562
+ def initialize(options = {})
563
+ @options = options.dup
564
+ @sts = @options.delete(:sts) || STS.new
565
+ end
566
+
567
+ def credentials
568
+ refresh if near_expiration?
569
+ super
570
+ end
571
+
572
+ private
573
+
574
+ def near_expiration?
575
+ @expiration && @expiration.utc <= Time.now.utc + 5 * 60
576
+ end
577
+
578
+ def get_credentials
579
+ role = @sts.assume_role(@options)
580
+ @expiration = role[:credentials][:expiration]
581
+ role[:credentials]
582
+ end
583
+
584
+ end
585
+
468
586
  # Returns a set of fake credentials, should only be used for testing.
469
587
  class FakeProvider < StaticProvider
470
588
 
@@ -228,10 +228,20 @@ module AWS
228
228
  def new options = {}
229
229
  options = pool_options(options)
230
230
  @pools_mutex.synchronize do
231
- @pools[options] ||= super(options)
231
+ @pools[options] ||= build(options)
232
232
  end
233
233
  end
234
234
 
235
+ # Constructs and returns a new connection pool. This pool is never
236
+ # shared.
237
+ # @option (see new)
238
+ # @return [ConnectionPool]
239
+ def build(options = {})
240
+ pool = allocate
241
+ pool.send(:initialize, pool_options(options))
242
+ pool
243
+ end
244
+
235
245
  # @return [Array<ConnectionPool>] Returns a list of of the constructed
236
246
  # connection pools.
237
247
  def pools
@@ -277,8 +287,18 @@ module AWS
277
287
  args << endpoint.port
278
288
  args << proxy_uri.host
279
289
  args << proxy_uri.port
280
- args << proxy_uri.user
281
- args << proxy_uri.password
290
+
291
+ if proxy_uri.user
292
+ args << URI::decode(proxy_uri.user)
293
+ else
294
+ args << nil
295
+ end
296
+
297
+ if proxy_uri.password
298
+ args << URI::decode(proxy_uri.password)
299
+ else
300
+ args << nil
301
+ end
282
302
 
283
303
  http = Net::HTTP.new(*args.compact)
284
304
  http.extend(SessionExtensions)
@@ -24,7 +24,7 @@ module AWS
24
24
  class NetHttpHandler
25
25
 
26
26
  class TruncatedBodyError < IOError; end
27
-
27
+
28
28
  # @api private
29
29
  NETWORK_ERRORS = [
30
30
  SocketError, EOFError, IOError, Timeout::Error,
@@ -34,7 +34,7 @@ module AWS
34
34
 
35
35
  # (see ConnectionPool.new)
36
36
  def initialize options = {}
37
- @pool = ConnectionPool.new(options)
37
+ @pool = options[:connection_pool] || ConnectionPool.new(options)
38
38
  @verify_content_length = options[:verify_response_body_content_length]
39
39
  end
40
40
 
@@ -58,33 +58,30 @@ module AWS
58
58
  http.continue_timeout = request.continue_timeout if
59
59
  http.respond_to?(:continue_timeout=)
60
60
 
61
+ exp_length = nil
62
+ act_length = 0
61
63
  http.request(build_net_http_request(request)) do |net_http_resp|
62
64
  response.status = net_http_resp.code.to_i
63
65
  response.headers = net_http_resp.to_hash
64
66
  exp_length = determine_expected_content_length(response)
65
- act_length = 0
66
- begin
67
- if block_given? and response.status < 300
68
- net_http_resp.read_body do |data|
69
- begin
70
- act_length += data.bytesize
71
- yield data
72
- ensure
73
- retry_possible = false
74
- end
67
+ if block_given? and response.status < 300
68
+ net_http_resp.read_body do |data|
69
+ begin
70
+ act_length += data.bytesize
71
+ yield data unless data.empty?
72
+ ensure
73
+ retry_possible = false
75
74
  end
76
- else
77
- response.body = net_http_resp.read_body
78
- act_length += response.body.bytesize unless response.body.nil?
79
- end
80
- ensure
81
- run_check = exp_length.nil? == false && request.http_method != "HEAD" && @verify_content_length
82
- if run_check && act_length != exp_length
83
- raise TruncatedBodyError, 'content-length does not match'
84
75
  end
76
+ else
77
+ response.body = net_http_resp.read_body
78
+ act_length += response.body.bytesize unless response.body.nil?
85
79
  end
86
80
  end
87
-
81
+ run_check = exp_length && request.http_method != "HEAD" && @verify_content_length
82
+ if run_check && act_length != exp_length
83
+ raise TruncatedBodyError, 'content-length does not match'
84
+ end
88
85
  end
89
86
 
90
87
  rescue *NETWORK_ERRORS => error
@@ -54,6 +54,9 @@ module AWS
54
54
  # to be populated for requests against signature v4 endpoints.
55
55
  attr_accessor :region
56
56
 
57
+ # @api private
58
+ attr_accessor :service
59
+
57
60
  # @return [String] Returns the AWS access key ID used to authorize the
58
61
  # request.
59
62
  # @api private
@@ -135,6 +138,13 @@ module AWS
135
138
  end
136
139
  end
137
140
 
141
+ # @api private
142
+ def remove_param(name)
143
+ if param = @params.find { |p| p.name == name }
144
+ @params.delete(param)
145
+ end
146
+ end
147
+
138
148
  # @api private
139
149
  # @return [String,nil] Returns the url encoded request params. If there
140
150
  # are no params, then nil is returned.
@@ -0,0 +1,42 @@
1
+ # Copyright 2011-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ module Core
16
+
17
+ # @api private
18
+ module IniParser
19
+
20
+ def self.parse(ini)
21
+ current_section = {}
22
+ map = {}
23
+ ini.split(/\r?\n/).each do |line|
24
+ line = line.split(/^|\s;/).first # remove comments
25
+ section = line.match(/^\s*\[([^\[\]]+)\]\s*$/) unless line.nil?
26
+ if section
27
+ current_section = section[1]
28
+ elsif current_section
29
+ item = line.match(/^\s*(.+?)\s*=\s*(.+)\s*$/) unless line.nil?
30
+ if item
31
+ map[current_section] = map[current_section] || {}
32
+ map[current_section][item[1]] = item[2]
33
+ end
34
+ end
35
+ end
36
+ map
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -67,7 +67,13 @@ module AWS
67
67
  # @return [nil]
68
68
  def const_missing constant
69
69
  const_missing_mutex.synchronize do
70
- const_set(constant, Class.new(Errors::Base) { extend LazyErrorClasses })
70
+ # It's possible the constant was defined by another thread while
71
+ # this thread was waiting on the mutex, check before setting.
72
+ if error_const_set?(constant)
73
+ const_get(constant)
74
+ else
75
+ const_set(constant, Class.new(Errors::Base) { extend LazyErrorClasses })
76
+ end
71
77
  end
72
78
  end
73
79
 
@@ -84,7 +90,19 @@ module AWS
84
90
  module_eval("#{self}::#{code.gsub('.Range','Range').gsub(".","::")}")
85
91
  end
86
92
 
87
- end
93
+ private
94
+
95
+ # @return [Boolean] Returns true if the constant is defined in the
96
+ # current module.
97
+ def error_const_set?(constant)
98
+ # Not using #const_defined? because in Ruby 1.9+, it returns true for
99
+ # constants not defined directly on the current module.
100
+ constant = constant.to_sym
101
+ # In Ruby 1.8, #constants returns an array of strings,
102
+ # in Ruby 1.9+, #constants returns an array of symbols.
103
+ constants.any? { |c| c.to_sym == constant }
104
+ end
88
105
 
106
+ end
89
107
  end
90
108
  end