aws-sdk 1.3.9 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. data/lib/aws.rb +2 -0
  2. data/lib/aws/api_config/CloudFormation-2010-05-15.yml +204 -0
  3. data/lib/aws/api_config/EC2-2011-12-15.yml +0 -2
  4. data/lib/aws/auto_scaling.rb +1 -1
  5. data/lib/aws/auto_scaling/group.rb +1 -1
  6. data/lib/aws/auto_scaling/instance.rb +4 -4
  7. data/lib/aws/auto_scaling/notification_configuration_collection.rb +2 -2
  8. data/lib/aws/cloud_formation.rb +287 -0
  9. data/lib/aws/cloud_formation/client.rb +33 -0
  10. data/lib/aws/cloud_formation/client/xml.rb +32 -0
  11. data/lib/aws/cloud_formation/config.rb +18 -0
  12. data/lib/aws/cloud_formation/errors.rb +26 -0
  13. data/lib/aws/cloud_formation/request.rb +30 -0
  14. data/lib/aws/cloud_formation/stack.rb +255 -0
  15. data/lib/aws/cloud_formation/stack_collection.rb +206 -0
  16. data/lib/aws/cloud_formation/stack_event.rb +75 -0
  17. data/lib/aws/cloud_formation/stack_event_collection.rb +47 -0
  18. data/lib/aws/cloud_formation/stack_options.rb +72 -0
  19. data/lib/aws/cloud_formation/stack_output.rb +53 -0
  20. data/lib/aws/cloud_formation/stack_resource.rb +117 -0
  21. data/lib/aws/cloud_formation/stack_resource_collection.rb +84 -0
  22. data/lib/aws/cloud_formation/stack_resource_summary_collection.rb +72 -0
  23. data/lib/aws/cloud_formation/stack_summary.rb +71 -0
  24. data/lib/aws/cloud_formation/stack_summary_collection.rb +127 -0
  25. data/lib/aws/core.rb +5 -1
  26. data/lib/aws/core/configuration.rb +4 -1
  27. data/lib/aws/core/resource.rb +16 -0
  28. data/lib/aws/core/response.rb +7 -5
  29. data/lib/aws/ec2/elastic_ip.rb +53 -4
  30. data/lib/aws/ec2/elastic_ip_collection.rb +20 -7
  31. data/lib/aws/ec2/instance.rb +28 -7
  32. data/lib/aws/simple_email_service.rb +4 -6
  33. data/lib/aws/sts/request.rb +7 -1
  34. metadata +23 -5
data/lib/aws.rb CHANGED
@@ -14,6 +14,7 @@
14
14
  require 'aws/core'
15
15
 
16
16
  require 'aws/auto_scaling/config'
17
+ require 'aws/cloud_formation/config'
17
18
  require 'aws/dynamo_db/config'
18
19
  require 'aws/ec2/config'
19
20
  require 'aws/elb/config'
@@ -29,6 +30,7 @@ require 'aws/sts/config'
29
30
  module AWS
30
31
  register_autoloads(self) do
31
32
  autoload :AutoScaling, 'auto_scaling'
33
+ autoload :CloudFormation, 'cloud_formation'
32
34
  autoload :DynamoDB, 'dynamo_db'
33
35
  autoload :EC2, 'ec2'
34
36
  autoload :ELB, 'elb'
@@ -0,0 +1,204 @@
1
+ # Copyright 2011-2012 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
+ ---
15
+ :operations:
16
+ CreateStack:
17
+ :input:
18
+ StackName:
19
+ - :string
20
+ - :required
21
+ TemplateBody:
22
+ - :string
23
+ TemplateURL:
24
+ - :string
25
+ Parameters:
26
+ - :membered_list:
27
+ - :structure:
28
+ ParameterKey:
29
+ - :string
30
+ ParameterValue:
31
+ - :string
32
+ DisableRollback:
33
+ - :boolean
34
+ TimeoutInMinutes:
35
+ - :integer
36
+ NotificationARNs:
37
+ - :membered_list:
38
+ - :string
39
+ Capabilities:
40
+ - :membered_list:
41
+ - :string
42
+ OnFailure:
43
+ - :string
44
+ :output: []
45
+ DeleteStack:
46
+ :input:
47
+ StackName:
48
+ - :string
49
+ - :required
50
+ :output: []
51
+ DescribeStacks:
52
+ :input:
53
+ StackName:
54
+ - :string
55
+ :output:
56
+ - Stacks:
57
+ - :list: member
58
+ - member:
59
+ - Parameters:
60
+ - :list: member
61
+ - CreationTime:
62
+ - :timestamp
63
+ - LastUpdatedTime:
64
+ - :timestamp
65
+ - DisableRollback:
66
+ - :boolean
67
+ - NotificationARNs:
68
+ - :list: member
69
+ - TimeoutInMinutes:
70
+ - :integer
71
+ - Capabilities:
72
+ - :list: member
73
+ - Outputs:
74
+ - :list: member
75
+ ListStacks:
76
+ :input:
77
+ NextToken:
78
+ - :string
79
+ StackStatusFilter:
80
+ - :membered_list:
81
+ - :string
82
+ :output:
83
+ - StackSummaries:
84
+ - :list: member
85
+ - member:
86
+ - CreationTime:
87
+ - :timestamp
88
+ - LastUpdatedTime:
89
+ - :timestamp
90
+ - DeletionTime:
91
+ - :timestamp
92
+ GetTemplate:
93
+ :input:
94
+ StackName:
95
+ - :string
96
+ - :required
97
+ :output: []
98
+ ListStackResources:
99
+ :input:
100
+ StackName:
101
+ - :string
102
+ - :required
103
+ NextToken:
104
+ - :string
105
+ :output:
106
+ - StackResourceSummaries:
107
+ - :list: member
108
+ - member:
109
+ - LastUpdatedTimestamp:
110
+ - :timestamp
111
+ DescribeStackResource:
112
+ :input:
113
+ StackName:
114
+ - :string
115
+ - :required
116
+ LogicalResourceId:
117
+ - :string
118
+ - :required
119
+ :output:
120
+ - StackResourceDetail:
121
+ - LastUpdatedTimestamp:
122
+ - :timestamp
123
+ DescribeStackResources:
124
+ :input:
125
+ StackName:
126
+ - :string
127
+ LogicalResourceId:
128
+ - :string
129
+ PhysicalResourceId:
130
+ - :string
131
+ :output:
132
+ - StackResources:
133
+ - :list: member
134
+ - member:
135
+ - Timestamp:
136
+ - :timestamp
137
+ UpdateStack:
138
+ :input:
139
+ StackName:
140
+ - :string
141
+ - :required
142
+ TemplateBody:
143
+ - :string
144
+ TemplateURL:
145
+ - :string
146
+ Parameters:
147
+ - :membered_list:
148
+ - :structure:
149
+ ParameterKey:
150
+ - :string
151
+ ParameterValue:
152
+ - :string
153
+ Capabilities:
154
+ - :membered_list:
155
+ - :string
156
+ :output: []
157
+ DescribeStackEvents:
158
+ :input:
159
+ StackName:
160
+ - :string
161
+ NextToken:
162
+ - :string
163
+ :output:
164
+ - StackEvents:
165
+ - :list: member
166
+ - member:
167
+ - Timestamp:
168
+ - :timestamp
169
+ ValidateTemplate:
170
+ :input:
171
+ TemplateBody:
172
+ - :string
173
+ TemplateURL:
174
+ - :string
175
+ :output:
176
+ - Parameters:
177
+ - :list: member
178
+ - member:
179
+ - NoEcho:
180
+ - :boolean
181
+ - Capabilities:
182
+ - :list: member
183
+ EstimateTemplateCost:
184
+ :input:
185
+ TemplateBody:
186
+ - :string
187
+ TemplateURL:
188
+ - :string
189
+ Parameters:
190
+ - :membered_list:
191
+ - :structure:
192
+ ParameterKey:
193
+ - :string
194
+ ParameterValue:
195
+ - :string
196
+ :output: []
197
+ CreateUploadBucket:
198
+ :input: {}
199
+ :output: []
200
+ :client_errors:
201
+ LimitExceededException: []
202
+ AlreadyExistsException: []
203
+ InsufficientCapabilitiesException: []
204
+ :server_errors: {}
@@ -25,7 +25,6 @@
25
25
  - :required
26
26
  PublicIp:
27
27
  - :string
28
- - :required
29
28
  AllocationId:
30
29
  - :string
31
30
  NetworkInterfaceId:
@@ -1004,7 +1003,6 @@
1004
1003
  :input:
1005
1004
  PublicIp:
1006
1005
  - :string
1007
- - :required
1008
1006
  AssociationId:
1009
1007
  - :string
1010
1008
  :output: []
@@ -115,7 +115,7 @@ module AWS
115
115
 
116
116
  # @return [AutoScaling::InstancesCollection] Returns a collection of
117
117
  # {AutoScaling::Instance} objects. Each of these is a small
118
- # wrapper around an {EC::Instance} with additional attributes.
118
+ # wrapper around an {EC2::Instance} with additional attributes.
119
119
  def instances
120
120
  InstanceCollection.new(:config => config)
121
121
  end
@@ -372,7 +372,7 @@ module AWS
372
372
  #
373
373
  # @see #delete!
374
374
  #
375
- # @params [Hash] options
375
+ # @param [Hash] options
376
376
  #
377
377
  # @option options [Boolean] :force (false) When true, the Auto Scaling
378
378
  # group will be deleted along with all instances associated with
@@ -18,10 +18,10 @@ module AWS
18
18
  #
19
19
  # == Getting Auto Scaling Instances
20
20
  #
21
- # If you know the EC2 instance id, you can use {#[]} to get the
22
- # Auto Scaling instance.
21
+ # If you know the EC2 instance id, you can use {InstanceCollection#[]}
22
+ # to get the Auto Scaling instance.
23
23
  #
24
- # instance = auto_scaling.instance['i-1234578']
24
+ # instance = auto_scaling.instances['i-1234578']
25
25
  # instance.health_statue #=> :healthy
26
26
  # instance.ec2_instance #=> <AWS::EC2::Instance instance_id:i-1234578>
27
27
  #
@@ -150,7 +150,7 @@ module AWS
150
150
 
151
151
  # Terminates the current Auto Scaling instance.
152
152
  #
153
- # @params [Boolean] decrement_desired_capacity Specifies whether or not
153
+ # @param [Boolean] decrement_desired_capacity Specifies whether or not
154
154
  # terminating this instance should also decrement the size of
155
155
  # the AutoScalingGroup.
156
156
  #
@@ -130,8 +130,8 @@ module AWS
130
130
  end
131
131
  alias_method :put, :create
132
132
 
133
- # @yeild [notification_config]
134
- # @yield_param [NotificationConfiguration] notification_config
133
+ # @yield [notification_config]
134
+ # @yieldparam [NotificationConfiguration] notification_config
135
135
  def each &block
136
136
 
137
137
  #
@@ -0,0 +1,287 @@
1
+ # Copyright 2011-2012 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
+ require 'aws/core'
15
+ require 'aws/cloud_formation/config'
16
+
17
+ module AWS
18
+
19
+ # = AWS::CloudFormation
20
+ #
21
+ # Provides an expressive, object-oriented interface to AWS CloudFormation.
22
+ #
23
+ # == Credentials
24
+ #
25
+ # You can setup default credentials for all AWS services via
26
+ # AWS.config:
27
+ #
28
+ # AWS.config(
29
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
30
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
31
+ #
32
+ # Or you can set them directly on the CloudFormation interface:
33
+ #
34
+ # cf = AWS::CloudFormation.new(
35
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
36
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
37
+ #
38
+ # = Stacks
39
+ #
40
+ # This is the starting point for working with CloudFormation.
41
+ #
42
+ # == Creating a Stack
43
+ #
44
+ # You can create a CloudFormation stack with a name and a template.
45
+ #
46
+ # template = <<-TEMPLATE
47
+ # {
48
+ # "AWSTemplateFormatVersion" : "2010-09-09",
49
+ # "Description": "A simple template",
50
+ # "Resources": {
51
+ # "web": {
52
+ # "Type": "AWS::EC2::Instance",
53
+ # "Properties": {
54
+ # "ImageId": "ami-41814f28"
55
+ # }
56
+ # }
57
+ # }
58
+ # }
59
+ # TEMPLATE
60
+ #
61
+ # cfm = AWS::CloudFormation.new
62
+ # stack = cfm.stacks.create('stack-name', template)
63
+ #
64
+ # See {StackCollection#create} for more information on creating templates
65
+ # with capabilities and parameters.
66
+ #
67
+ # == Getting a Stack
68
+ #
69
+ # Given a name, you can fetch a {Stack}.
70
+ #
71
+ # stack = cfm.stacks['stack-name']
72
+ #
73
+ # == Enumerating Stacks
74
+ #
75
+ # You can enumerate stacks in two ways. You can enumerate {Stack}
76
+ # objects or stack summaries (simple hashes). You can filter the stack
77
+ # summary collection by a status.
78
+ #
79
+ # # enumerating all stack objects
80
+ # cfm.stacks.each do |stack|
81
+ # # ...
82
+ # end
83
+ #
84
+ # # enumerating stack summaries (hashes)
85
+ # cfm.stack_summaries.each do |stack_summary|
86
+ # # ...
87
+ # end
88
+ #
89
+ # # filtering stack summaries by status
90
+ # cfm.stack_summaries.with_status(:create_failed).each do |summary|
91
+ # puts summary.to_yaml
92
+ # end
93
+ #
94
+ # == Template
95
+ #
96
+ # You can fetch the template body for a stack as a JSON string.
97
+ #
98
+ # cfm.stacks['stack-name'].template
99
+ # #=> "{...}"
100
+ #
101
+ # You can update the template for a {Stack} with the {Stack#update} method:
102
+ #
103
+ # cfm.stacks['stack-name'].update(:template => new_template)
104
+ #
105
+ # == Stack Events
106
+ #
107
+ # You can enumerate events for a stack.
108
+ #
109
+ # stack.events.each do |event|
110
+ # puts "#{event.physical_resource_id}: #{event.resource_status}"
111
+ # end
112
+ #
113
+ # See {StackEvent} for a complete list of event attributes.
114
+ #
115
+ # == Stack Resources
116
+ #
117
+ # You can enumerate stack resources or request a stack resource by its
118
+ # logical resource id.
119
+ #
120
+ # # enumerating stack resources
121
+ # stack.resources.each do |resource|
122
+ # # ...
123
+ # end
124
+ #
125
+ # # getting a resource by its logical id
126
+ # res = stack.resources['logical-resource-id']
127
+ # puts res.physical_resource_id
128
+ #
129
+ # If you need a stack resource, but only have its physical resource
130
+ # id, then you can call {CloudFormation#stack_resource}.
131
+ #
132
+ # stack_resource = cfm.stack_resource('physical-resource-id')
133
+ #
134
+ # == Stack Resource Summaries
135
+ #
136
+ # As an alternative to stack resources, you can enumerate stack
137
+ # resource summaries (hashes).
138
+ #
139
+ # # enumerate all resources, this collection can not be filtered
140
+ # stack.resource_summaries.each do |summary|
141
+ # # ...
142
+ # end
143
+ #
144
+ class CloudFormation
145
+
146
+ AWS.register_autoloads(self, 'aws/cloud_formation') do
147
+ autoload :Client, 'client'
148
+ autoload :Errors, 'errors'
149
+ autoload :Request, 'request'
150
+ autoload :Stack, 'stack'
151
+ autoload :StackCollection, 'stack_collection'
152
+ autoload :StackEvent, 'stack_event'
153
+ autoload :StackEventCollection, 'stack_event_collection'
154
+ autoload :StackOptions, 'stack_options'
155
+ autoload :StackOutput, 'stack_output'
156
+ autoload :StackSummaryCollection, 'stack_summary_collection'
157
+ autoload :StackResource, 'stack_resource'
158
+ autoload :StackResourceCollection, 'stack_resource_collection'
159
+ autoload :StackResourceSummaryCollection, 'stack_resource_summary_collection'
160
+ end
161
+
162
+ include Core::ServiceInterface
163
+ include StackOptions
164
+
165
+ # @return [StackCollection]
166
+ def stacks
167
+ StackCollection.new(:config => config)
168
+ end
169
+
170
+ # @return [StackSummaryCollection]
171
+ def stack_summaries
172
+ StackSummaryCollection.new(:config => config)
173
+ end
174
+
175
+ # Returns a stack resource with the given physical resource
176
+ # id.
177
+ #
178
+ # resource = cfm.stack_resource('i-123456789')
179
+ #
180
+ # Alternatively, you may pass a stack name and logical resource id:
181
+ #
182
+ # resource = cfm.stack_resource('stack-name', 'logical-resource-id')
183
+ #
184
+ # @overload stack_resource(physical_resource_id)
185
+ # @param [String] physical_resource_id The physical resource id
186
+ # of the stack resource you want returned.
187
+ #
188
+ # @overload stack_resource(stack_name, logical_resource_id)
189
+ # @param [String] stack_name
190
+ # @param [String] logical_resource_id
191
+ #
192
+ # @return [StackResource] Returns the stack resource with the
193
+ # given physical resource id.
194
+ #
195
+ def stack_resource *args
196
+
197
+ client_opts = {}
198
+
199
+ if args.size == 1
200
+ client_opts[:physical_resource_id] = args.first
201
+ else
202
+ client_opts[:stack_name] = args[0]
203
+ client_opts[:logical_resource_id] = args[1]
204
+ end
205
+
206
+ response = client.describe_stack_resources(client_opts)
207
+
208
+ details = response.stack_resources.first
209
+
210
+ StackResource.new_from(
211
+ :describe_stack_resource, details,
212
+ Stack.new(details.stack_name, :config => config),
213
+ details.logical_resource_id)
214
+
215
+ end
216
+
217
+ # Validates the template and returns a hash. If the template is valid,
218
+ # the returned hash may/will contain the following keys (actual
219
+ # key list depends on the template).
220
+ #
221
+ # * +:description+
222
+ # * +:capabilities+
223
+ # * +:capabilities_reason+
224
+ # * +:parameters+
225
+ #
226
+ # If the template is not parseable, then a hash will the following
227
+ # keys will be returned:
228
+ #
229
+ # * +:code+
230
+ # * +:message+
231
+ #
232
+ # @return [Hash]
233
+ #
234
+ def validate_template template
235
+ begin
236
+
237
+ client_opts = {}
238
+ client_opts[:template] = template
239
+ apply_template(client_opts)
240
+ resp = client.validate_template(client_opts)
241
+
242
+ results = {}
243
+ [
244
+ :capabilities,
245
+ :capabilities_reason,
246
+ :description,
247
+ ].each do |method|
248
+ if resp.respond_to?(method)
249
+ results[method] = resp.send(method)
250
+ end
251
+ end
252
+
253
+ if resp.respond_to?(:parameters)
254
+ results[:parameters] = resp.parameters.collect(&:to_hash)
255
+ end
256
+
257
+ results
258
+
259
+ rescue CloudFormation::Errors::ValidationError => e
260
+
261
+ results = {}
262
+ results[:code] = e.code
263
+ results[:message] = e.message
264
+ results
265
+
266
+ end
267
+ end
268
+
269
+ # @param (see Stack#template=)
270
+ #
271
+ # @param [Hash] parameters A hash that specifies the input
272
+ # parameters for the template.
273
+ #
274
+ # @return [String] Returns a URL to the AWS Simple Monthly Calculator
275
+ # with a query string that describes the resources required to run
276
+ # the template.
277
+ #
278
+ def estimate_template_cost template, parameters = {}
279
+ client_opts = {}
280
+ client_opts[:template] = template
281
+ apply_template(client_opts)
282
+ apply_parameters(client_opts)
283
+ client.estimate_template_cost(client_opts).url
284
+ end
285
+
286
+ end
287
+ end