aws-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/.yardopts +6 -0
  2. data/LICENSE.txt +171 -0
  3. data/NOTICE.txt +2 -0
  4. data/README.rdoc +189 -0
  5. data/lib/aws-sdk.rb +14 -0
  6. data/lib/aws.rb +63 -0
  7. data/lib/aws/api_config.rb +45 -0
  8. data/lib/aws/api_config/.document +0 -0
  9. data/lib/aws/api_config/EC2-2011-02-28.yml +2314 -0
  10. data/lib/aws/api_config/SNS-2010-03-31.yml +171 -0
  11. data/lib/aws/api_config/SQS-2009-02-01.yml +161 -0
  12. data/lib/aws/api_config/SimpleDB-2009-04-15.yml +278 -0
  13. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +147 -0
  14. data/lib/aws/api_config_transform.rb +32 -0
  15. data/lib/aws/async_handle.rb +90 -0
  16. data/lib/aws/authorize_v2.rb +37 -0
  17. data/lib/aws/authorize_v3.rb +37 -0
  18. data/lib/aws/base_client.rb +524 -0
  19. data/lib/aws/cacheable.rb +92 -0
  20. data/lib/aws/common.rb +228 -0
  21. data/lib/aws/configurable.rb +36 -0
  22. data/lib/aws/configuration.rb +272 -0
  23. data/lib/aws/configured_client_methods.rb +81 -0
  24. data/lib/aws/configured_grammars.rb +65 -0
  25. data/lib/aws/configured_option_grammars.rb +46 -0
  26. data/lib/aws/configured_xml_grammars.rb +47 -0
  27. data/lib/aws/default_signer.rb +38 -0
  28. data/lib/aws/ec2.rb +321 -0
  29. data/lib/aws/ec2/attachment.rb +149 -0
  30. data/lib/aws/ec2/attachment_collection.rb +57 -0
  31. data/lib/aws/ec2/availability_zone.rb +80 -0
  32. data/lib/aws/ec2/availability_zone_collection.rb +47 -0
  33. data/lib/aws/ec2/block_device_mappings.rb +53 -0
  34. data/lib/aws/ec2/client.rb +54 -0
  35. data/lib/aws/ec2/client/xml.rb +127 -0
  36. data/lib/aws/ec2/collection.rb +39 -0
  37. data/lib/aws/ec2/config_transform.rb +63 -0
  38. data/lib/aws/ec2/elastic_ip.rb +107 -0
  39. data/lib/aws/ec2/elastic_ip_collection.rb +85 -0
  40. data/lib/aws/ec2/errors.rb +29 -0
  41. data/lib/aws/ec2/filtered_collection.rb +65 -0
  42. data/lib/aws/ec2/has_permissions.rb +46 -0
  43. data/lib/aws/ec2/image.rb +245 -0
  44. data/lib/aws/ec2/image_collection.rb +235 -0
  45. data/lib/aws/ec2/instance.rb +515 -0
  46. data/lib/aws/ec2/instance_collection.rb +276 -0
  47. data/lib/aws/ec2/key_pair.rb +86 -0
  48. data/lib/aws/ec2/key_pair_collection.rb +102 -0
  49. data/lib/aws/ec2/permission_collection.rb +177 -0
  50. data/lib/aws/ec2/region.rb +81 -0
  51. data/lib/aws/ec2/region_collection.rb +55 -0
  52. data/lib/aws/ec2/request.rb +27 -0
  53. data/lib/aws/ec2/reserved_instances.rb +50 -0
  54. data/lib/aws/ec2/reserved_instances_collection.rb +44 -0
  55. data/lib/aws/ec2/reserved_instances_offering.rb +55 -0
  56. data/lib/aws/ec2/reserved_instances_offering_collection.rb +43 -0
  57. data/lib/aws/ec2/resource.rb +340 -0
  58. data/lib/aws/ec2/resource_tag_collection.rb +218 -0
  59. data/lib/aws/ec2/security_group.rb +246 -0
  60. data/lib/aws/ec2/security_group/ip_permission.rb +70 -0
  61. data/lib/aws/ec2/security_group/ip_permission_collection.rb +59 -0
  62. data/lib/aws/ec2/security_group_collection.rb +132 -0
  63. data/lib/aws/ec2/snapshot.rb +138 -0
  64. data/lib/aws/ec2/snapshot_collection.rb +90 -0
  65. data/lib/aws/ec2/tag.rb +88 -0
  66. data/lib/aws/ec2/tag_collection.rb +114 -0
  67. data/lib/aws/ec2/tagged_collection.rb +48 -0
  68. data/lib/aws/ec2/tagged_item.rb +87 -0
  69. data/lib/aws/ec2/volume.rb +190 -0
  70. data/lib/aws/ec2/volume_collection.rb +95 -0
  71. data/lib/aws/errors.rb +129 -0
  72. data/lib/aws/http/builtin_handler.rb +69 -0
  73. data/lib/aws/http/curb_handler.rb +123 -0
  74. data/lib/aws/http/handler.rb +77 -0
  75. data/lib/aws/http/httparty_handler.rb +61 -0
  76. data/lib/aws/http/request.rb +136 -0
  77. data/lib/aws/http/request_param.rb +63 -0
  78. data/lib/aws/http/response.rb +75 -0
  79. data/lib/aws/ignore_result_element.rb +38 -0
  80. data/lib/aws/indifferent_hash.rb +86 -0
  81. data/lib/aws/inflection.rb +46 -0
  82. data/lib/aws/lazy_error_classes.rb +64 -0
  83. data/lib/aws/meta_utils.rb +43 -0
  84. data/lib/aws/model.rb +57 -0
  85. data/lib/aws/naming.rb +32 -0
  86. data/lib/aws/option_grammar.rb +544 -0
  87. data/lib/aws/policy.rb +912 -0
  88. data/lib/aws/rails.rb +209 -0
  89. data/lib/aws/record.rb +79 -0
  90. data/lib/aws/record/attribute.rb +94 -0
  91. data/lib/aws/record/attribute_macros.rb +288 -0
  92. data/lib/aws/record/attributes/boolean.rb +49 -0
  93. data/lib/aws/record/attributes/datetime.rb +86 -0
  94. data/lib/aws/record/attributes/float.rb +48 -0
  95. data/lib/aws/record/attributes/integer.rb +68 -0
  96. data/lib/aws/record/attributes/sortable_float.rb +60 -0
  97. data/lib/aws/record/attributes/sortable_integer.rb +95 -0
  98. data/lib/aws/record/attributes/string.rb +69 -0
  99. data/lib/aws/record/base.rb +728 -0
  100. data/lib/aws/record/conversion.rb +38 -0
  101. data/lib/aws/record/dirty_tracking.rb +286 -0
  102. data/lib/aws/record/errors.rb +153 -0
  103. data/lib/aws/record/exceptions.rb +48 -0
  104. data/lib/aws/record/finder_methods.rb +262 -0
  105. data/lib/aws/record/naming.rb +31 -0
  106. data/lib/aws/record/scope.rb +157 -0
  107. data/lib/aws/record/validations.rb +653 -0
  108. data/lib/aws/record/validator.rb +237 -0
  109. data/lib/aws/record/validators/acceptance.rb +51 -0
  110. data/lib/aws/record/validators/block.rb +38 -0
  111. data/lib/aws/record/validators/confirmation.rb +43 -0
  112. data/lib/aws/record/validators/count.rb +108 -0
  113. data/lib/aws/record/validators/exclusion.rb +43 -0
  114. data/lib/aws/record/validators/format.rb +57 -0
  115. data/lib/aws/record/validators/inclusion.rb +56 -0
  116. data/lib/aws/record/validators/length.rb +107 -0
  117. data/lib/aws/record/validators/numericality.rb +138 -0
  118. data/lib/aws/record/validators/presence.rb +45 -0
  119. data/lib/aws/resource_cache.rb +39 -0
  120. data/lib/aws/response.rb +113 -0
  121. data/lib/aws/response_cache.rb +50 -0
  122. data/lib/aws/s3.rb +109 -0
  123. data/lib/aws/s3/access_control_list.rb +252 -0
  124. data/lib/aws/s3/acl_object.rb +266 -0
  125. data/lib/aws/s3/bucket.rb +320 -0
  126. data/lib/aws/s3/bucket_collection.rb +122 -0
  127. data/lib/aws/s3/bucket_version_collection.rb +85 -0
  128. data/lib/aws/s3/client.rb +999 -0
  129. data/lib/aws/s3/client/xml.rb +190 -0
  130. data/lib/aws/s3/data_options.rb +99 -0
  131. data/lib/aws/s3/errors.rb +43 -0
  132. data/lib/aws/s3/multipart_upload.rb +318 -0
  133. data/lib/aws/s3/multipart_upload_collection.rb +78 -0
  134. data/lib/aws/s3/object_collection.rb +159 -0
  135. data/lib/aws/s3/object_metadata.rb +67 -0
  136. data/lib/aws/s3/object_upload_collection.rb +83 -0
  137. data/lib/aws/s3/object_version.rb +141 -0
  138. data/lib/aws/s3/object_version_collection.rb +78 -0
  139. data/lib/aws/s3/paginated_collection.rb +94 -0
  140. data/lib/aws/s3/policy.rb +76 -0
  141. data/lib/aws/s3/prefix_and_delimiter_collection.rb +56 -0
  142. data/lib/aws/s3/prefixed_collection.rb +84 -0
  143. data/lib/aws/s3/presigned_post.rb +504 -0
  144. data/lib/aws/s3/request.rb +198 -0
  145. data/lib/aws/s3/s3_object.rb +794 -0
  146. data/lib/aws/s3/tree.rb +116 -0
  147. data/lib/aws/s3/tree/branch_node.rb +71 -0
  148. data/lib/aws/s3/tree/child_collection.rb +108 -0
  149. data/lib/aws/s3/tree/leaf_node.rb +99 -0
  150. data/lib/aws/s3/tree/node.rb +22 -0
  151. data/lib/aws/s3/tree/parent.rb +90 -0
  152. data/lib/aws/s3/uploaded_part.rb +82 -0
  153. data/lib/aws/s3/uploaded_part_collection.rb +86 -0
  154. data/lib/aws/service_interface.rb +60 -0
  155. data/lib/aws/simple_db.rb +202 -0
  156. data/lib/aws/simple_db/attribute.rb +159 -0
  157. data/lib/aws/simple_db/attribute_collection.rb +227 -0
  158. data/lib/aws/simple_db/client.rb +52 -0
  159. data/lib/aws/simple_db/client/options.rb +34 -0
  160. data/lib/aws/simple_db/client/xml.rb +68 -0
  161. data/lib/aws/simple_db/consistent_read_option.rb +42 -0
  162. data/lib/aws/simple_db/delete_attributes.rb +64 -0
  163. data/lib/aws/simple_db/domain.rb +118 -0
  164. data/lib/aws/simple_db/domain_collection.rb +116 -0
  165. data/lib/aws/simple_db/domain_metadata.rb +112 -0
  166. data/lib/aws/simple_db/errors.rb +46 -0
  167. data/lib/aws/simple_db/expect_condition_option.rb +45 -0
  168. data/lib/aws/simple_db/item.rb +84 -0
  169. data/lib/aws/simple_db/item_collection.rb +594 -0
  170. data/lib/aws/simple_db/item_data.rb +70 -0
  171. data/lib/aws/simple_db/put_attributes.rb +62 -0
  172. data/lib/aws/simple_db/request.rb +27 -0
  173. data/lib/aws/simple_email_service.rb +373 -0
  174. data/lib/aws/simple_email_service/client.rb +39 -0
  175. data/lib/aws/simple_email_service/client/options.rb +24 -0
  176. data/lib/aws/simple_email_service/client/xml.rb +38 -0
  177. data/lib/aws/simple_email_service/email_address_collection.rb +66 -0
  178. data/lib/aws/simple_email_service/errors.rb +29 -0
  179. data/lib/aws/simple_email_service/quotas.rb +64 -0
  180. data/lib/aws/simple_email_service/request.rb +27 -0
  181. data/lib/aws/sns.rb +69 -0
  182. data/lib/aws/sns/client.rb +37 -0
  183. data/lib/aws/sns/client/options.rb +24 -0
  184. data/lib/aws/sns/client/xml.rb +38 -0
  185. data/lib/aws/sns/errors.rb +29 -0
  186. data/lib/aws/sns/policy.rb +49 -0
  187. data/lib/aws/sns/request.rb +27 -0
  188. data/lib/aws/sns/subscription.rb +100 -0
  189. data/lib/aws/sns/subscription_collection.rb +84 -0
  190. data/lib/aws/sns/topic.rb +384 -0
  191. data/lib/aws/sns/topic_collection.rb +70 -0
  192. data/lib/aws/sns/topic_subscription_collection.rb +58 -0
  193. data/lib/aws/sqs.rb +70 -0
  194. data/lib/aws/sqs/client.rb +38 -0
  195. data/lib/aws/sqs/client/xml.rb +36 -0
  196. data/lib/aws/sqs/errors.rb +33 -0
  197. data/lib/aws/sqs/policy.rb +50 -0
  198. data/lib/aws/sqs/queue.rb +507 -0
  199. data/lib/aws/sqs/queue_collection.rb +105 -0
  200. data/lib/aws/sqs/received_message.rb +184 -0
  201. data/lib/aws/sqs/received_sns_message.rb +112 -0
  202. data/lib/aws/sqs/request.rb +44 -0
  203. data/lib/aws/xml_grammar.rb +923 -0
  204. data/rails/init.rb +15 -0
  205. metadata +298 -0
@@ -0,0 +1,81 @@
1
+ # Copyright 2011 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/api_config'
15
+ require 'aws/inflection'
16
+ require 'aws/configured_xml_grammars'
17
+ require 'aws/configured_option_grammars'
18
+
19
+ module AWS
20
+
21
+ # @private
22
+ module ConfiguredClientMethods
23
+
24
+ # @private
25
+ module ClassMethods
26
+
27
+ include ApiConfig
28
+
29
+ def configure_client
30
+
31
+ super
32
+
33
+ unless self::XML.include?(ConfiguredXmlGrammars)
34
+ self::XML.module_eval do
35
+ include(ConfiguredXmlGrammars)
36
+ define_configured_grammars
37
+ end
38
+ end
39
+
40
+ unless self::Options.include?(ConfiguredOptionGrammars)
41
+ self::Options.module_eval do
42
+ include(ConfiguredOptionGrammars)
43
+ define_configured_grammars
44
+ end
45
+ end
46
+
47
+ api_config[:operations].each do |name, customizations|
48
+ option_grammar = self::Options.operation_grammar(name)
49
+ add_client_request_method(Inflection.ruby_name(name).to_sym,
50
+ :xml_grammar =>
51
+ self::XML.operation_grammar(name)) do
52
+ configure_request do |request, options|
53
+ request.add_param("Action", name)
54
+ option_grammar.request_params(options).each do |param|
55
+ request.add_param(param)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ def operation_xml_grammar(name)
64
+ customized_name = "Customized#{name}"
65
+ if self::XML.const_defined?(customized_name)
66
+ self::XML.const_get(customized_name)
67
+ else
68
+ self::XML.const_get(name)
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ def self.included(mod)
75
+ mod.extend(ClassMethods)
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
@@ -0,0 +1,65 @@
1
+ # Copyright 2011 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/api_config'
15
+ require 'aws/xml_grammar'
16
+
17
+ module AWS
18
+
19
+ # @private
20
+ module ConfiguredGrammars
21
+
22
+ # @private
23
+ module ClassMethods
24
+
25
+ include ApiConfig
26
+
27
+ def base_grammar
28
+ raise NotImplementedError
29
+ end
30
+
31
+ def operation_grammar(name)
32
+ customized_name = "Customized#{name}"
33
+ if const_defined?(customized_name)
34
+ const_get(customized_name)
35
+ else
36
+ const_get(name)
37
+ end
38
+ end
39
+
40
+ def input_or_output
41
+ raise NotImplementedError
42
+ end
43
+
44
+ def process_customizations(name, customizations)
45
+ customizations
46
+ end
47
+
48
+ def define_configured_grammars
49
+ api_config[:operations].each do |name, data|
50
+ customizations = process_customizations(name,
51
+ data[input_or_output])
52
+ const_set(name,
53
+ base_grammar.customize(customizations))
54
+ # BaseResponse.customize([{
55
+ # "#{name}Result" =>
56
+ # [:ignore, *data[:output]]
57
+ # }]))
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright 2011 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/configured_grammars'
15
+ require 'aws/option_grammar'
16
+
17
+ module AWS
18
+
19
+ # @private
20
+ module ConfiguredOptionGrammars
21
+
22
+ module ClassMethods
23
+
24
+ include ConfiguredGrammars::ClassMethods
25
+
26
+ def base_grammar
27
+ if const_defined?(:BaseOptions)
28
+ const_get(:BaseOptions)
29
+ else
30
+ OptionGrammar
31
+ end
32
+ end
33
+
34
+ def input_or_output
35
+ :input
36
+ end
37
+
38
+ end
39
+
40
+ def self.included(mod)
41
+ mod.extend(ClassMethods)
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,47 @@
1
+ # Copyright 2011 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/configured_grammars'
15
+ require 'aws/xml_grammar'
16
+
17
+ module AWS
18
+
19
+ # @private
20
+ module ConfiguredXmlGrammars
21
+
22
+ # @private
23
+ module ClassMethods
24
+
25
+ include ConfiguredGrammars::ClassMethods
26
+
27
+ def base_grammar
28
+ if const_defined?(:BaseResponse)
29
+ const_get(:BaseResponse)
30
+ else
31
+ XmlGrammar
32
+ end
33
+ end
34
+
35
+ def input_or_output
36
+ :output
37
+ end
38
+
39
+ end
40
+
41
+ def self.included(mod)
42
+ mod.extend(ClassMethods)
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,38 @@
1
+ # Copyright 2011 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 'base64'
15
+ require 'openssl'
16
+
17
+ module AWS
18
+
19
+ # @private
20
+ class DefaultSigner
21
+
22
+ attr_reader :access_key_id, :secret_access_key
23
+
24
+ def initialize(access_key_id, secret_access_key)
25
+ @access_key_id = access_key_id
26
+ @secret_access_key = secret_access_key
27
+ end
28
+
29
+ def sign(string_to_sign, digest_method = 'sha256')
30
+ Base64.encode64(
31
+ OpenSSL::HMAC.digest(
32
+ OpenSSL::Digest::Digest.new(digest_method),
33
+ secret_access_key,
34
+ string_to_sign)).strip
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,321 @@
1
+ # Copyright 2011 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/common'
15
+ require 'aws/service_interface'
16
+ require 'aws/ec2/client'
17
+ require 'aws/ec2/instance_collection'
18
+ require 'aws/ec2/security_group_collection'
19
+ require 'aws/ec2/elastic_ip_collection'
20
+ require 'aws/ec2/key_pair_collection'
21
+ require 'aws/ec2/tag_collection'
22
+ require 'aws/ec2/region_collection'
23
+ require 'aws/ec2/availability_zone_collection'
24
+ require 'aws/ec2/image_collection'
25
+ require 'aws/ec2/volume_collection'
26
+ require 'aws/ec2/snapshot_collection'
27
+ require 'aws/ec2/reserved_instances_collection'
28
+ require 'aws/ec2/reserved_instances_offering_collection'
29
+
30
+ module AWS
31
+
32
+ # Provides an expressive, object-oriented interface to Amazon EC2.
33
+ #
34
+ # == Credentials
35
+ #
36
+ # You can setup default credentials for all AWS services via
37
+ # AWS.config:
38
+ #
39
+ # AWS.config(
40
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
41
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
42
+ #
43
+ # Or you can set them directly on the EC2 interface:
44
+ #
45
+ # ec2 = AWS::EC2.new(
46
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
47
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
48
+ #
49
+ # == Instances
50
+ #
51
+ # EC2 uses instances to run your software.
52
+ #
53
+ # To run an instance:
54
+ #
55
+ # ec2.instances.create(:image_id => "ami-8c1fece5")
56
+ #
57
+ # To get an instance by ID:
58
+ #
59
+ # i = ec2.instances["i-12345678"]
60
+ # i.exists?
61
+ #
62
+ # To get a list of instances:
63
+ #
64
+ # ec2.instances.inject({}) { |m, i| m[i.id] = i.status; m }
65
+ # # => { "i-12345678" => :running, "i-87654321" => :shutting_down }
66
+ #
67
+ # == Security Groups
68
+ #
69
+ # A security group is a named collection of access rules. These access
70
+ # rules specify which ingress (i.e., incoming) network traffic should be
71
+ # delivered to your instance. All other ingress traffic will be discarded.
72
+ #
73
+ # To create a security group:
74
+ #
75
+ # websvr = ec2.security_groups.create('webservers')
76
+ #
77
+ # Then you can add ingress authorizations. In the following example
78
+ # we add a rule that allows web traffic from the entire internet.
79
+ #
80
+ # # web traffic
81
+ # websvr.authorize_ingress(:tcp, 80)
82
+ #
83
+ # You can also specify a port range. Here we are opening FTP traffic:
84
+ #
85
+ # # ftp traffic
86
+ # websvr.authorize_ingress(:tcp, 20..21)
87
+ #
88
+ # If you want to limit an authorization to a particular CIDR IP address or
89
+ # list of address, just add them to the #authorize_ingress call.
90
+ #
91
+ # # ssh access
92
+ # websrvr.authorize_ingress(:tcp, 22, '1.1.1.1/0', '2.2.2.2/0')
93
+ #
94
+ # You can also provide another security group instead of CIDR IP addresses.
95
+ # This allows incoming traffic from EC2 instances in the given security
96
+ # group(s).
97
+ #
98
+ # # get two existing security groups
99
+ # dbsvrs = ec2.security_groups['db-servers']
100
+ # websvrs = ec2.security_groups['web-servers']
101
+ #
102
+ # # allow instances in the 'web-servers' security group to connect
103
+ # # to instances in the 'db-servers' security group over tcp port 3306
104
+ # dbsvrs.authorize_ingress(:tcp, 3306, websvrs)
105
+ #
106
+ # There are a few handy shortcuts for allowing pings:
107
+ #
108
+ # wbsvrs.allow_ping
109
+ #
110
+ # Just like with authorize_ingress you can pass a security group or a list
111
+ # of CIDR IP addresses to allow ping to limit where you can ping from.
112
+ #
113
+ # You can also use the same parameters from the examples above to
114
+ # {SecurityGroup#revoke_ingress} and {SecurityGroup#disallow_ping}.
115
+ #
116
+ # You can specify other protocols than +:tcp+, like :udp and :icmp.
117
+ #
118
+ # == Elastic IPs
119
+ #
120
+ # You can allocate up to 5 elastic IP addresses for each account.
121
+ # You can associate those elastic IP addresses with EC2 instances:
122
+ #
123
+ # instance = ec2.instances['i-12345678']
124
+ # ip = ec2.elastic_ips.allocate
125
+ #
126
+ # instance.ip_address # 1.1.1.1
127
+ # ip.ip_address # 2.2.2.2
128
+ #
129
+ # instance.associate_elastic_ip(ip)
130
+ # instance.ip_address # 2.2.2.2
131
+ #
132
+ # instance.disassociate_elastic_ip
133
+ # instance.ip_address # 1.1.1.1
134
+ #
135
+ # When you are done with an elastic IP address you should release it.
136
+ # In the following example we release all elastic IP addresses that are
137
+ # not currently associated with an instance:
138
+ #
139
+ # ec2.select{|ip| !ip.associated? }.each(&:release)
140
+ #
141
+ # == Key Pairs
142
+ #
143
+ # Public Amazon Machine Image (AMI) instances have no password, and you need a
144
+ # public/private key pair to log in to them. The public key half
145
+ # of this pair is embedded in your instance, allowing you to use
146
+ # the private key to log in securely without a password.
147
+ #
148
+ # You can generate a key pair yourself and then send the public
149
+ # part to EC2 using {KeyPairCollection#import}. For example:
150
+ #
151
+ # key_pair =
152
+ # ec2.key_pairs.import("mykey", File.read("~/.ssh/identity.pub"))
153
+ #
154
+ # You can also ask EC2 to generate a key pair for you. For
155
+ # example:
156
+ #
157
+ # key_pair = ec2.key_pairs.create("mykey")
158
+ # File.open("~/.ssh/ec2", "w") do |f|
159
+ # f.write(key_pair.private_key)
160
+ # end
161
+ #
162
+ # == Filtering and Tagging
163
+ #
164
+ # Any of the collections in the interface may be filtered by a
165
+ # number of different parameters. For example, to get all the
166
+ # windows images owned by amazon where the description includes
167
+ # the string "linux", you can do this:
168
+ #
169
+ # ec2.images.with_owner("amazon").
170
+ # filtered("platform", "windows").
171
+ # filtered("description", "*linux*")
172
+ #
173
+ # Similarly, you can tag images, instances, security groups,
174
+ # snapshots, and volumes with free-form key-value metadata and
175
+ # filter on that metadata. For example:
176
+ #
177
+ # ec2.images["ami-123"].tags << "myapp"
178
+ # ec2.images.tagged("myapp") # will include ami-123
179
+ #
180
+ # == Regions
181
+ #
182
+ # Amazon has data centers in different areas of the world (e.g.,
183
+ # North America, Europe, Asia, etc.). Correspondingly, EC2 is
184
+ # available to use in different Regions. By launching instances in
185
+ # separate Regions, you can design your application to be closer
186
+ # to specific customers or to meet legal or other
187
+ # requirements. Prices for Amazon EC2 usage vary by Region (for
188
+ # more information about pricing by Region, go to the {Amazon EC2
189
+ # Pricing page}[http://aws.amazon.com/ec2/pricing]). You can use
190
+ # the Ruby SDK to see which regions are available for your
191
+ # account:
192
+ #
193
+ # ec2.regions.map(&:name) # => ["us-east-1", ...]
194
+ #
195
+ # The default region is +us-east-1+; you can access other regions
196
+ # like this:
197
+ #
198
+ # ec2_us_west = ec2.regions["us-west-1"]
199
+ # # starts an instance in eu-west-1
200
+ # ec2_us_west.instances.create(:image_id => 'ami-3bc9997e')
201
+ #
202
+ # This makes a call to EC2's DescribeRegions API to find the
203
+ # endpoint for "us-west-1" -- if you just want to configure a
204
+ # different endpoint without making a call to EC2, you can do it
205
+ # like this:
206
+ #
207
+ # ec2 = AWS::EC2.new(:ec2_endpoint =>
208
+ # "ec2.us-west-1.amazonaws.com")
209
+ #
210
+ # == Availability Zones
211
+ #
212
+ # Each Region contains multiple distinct locations called
213
+ # Availability Zones. Each Availability Zone is engineered to be
214
+ # isolated from failures in other Availability zones and to
215
+ # provide inexpensive, low-latency network connectivity to other
216
+ # zones in the same Region. By launching instances in separate
217
+ # Availability Zones, you can protect your applications from the
218
+ # failure of a single location.
219
+ #
220
+ # You can use the {#availability_zones} collection to get information
221
+ # about the available zones available to your account. For
222
+ # example:
223
+ #
224
+ # ec2.availability_zones.map(&:name) # => ["us-east-1a", ...]
225
+ #
226
+ # == Images
227
+ #
228
+ # An Amazon Machine Image (AMI) contains all information necessary
229
+ # to boot instances of your software. For example, an AMI might
230
+ # contain all the software to act as a web server (e.g., Linux,
231
+ # Apache, and your web site) or it might contain all the software
232
+ # to act as a Hadoop node (e.g., Linux, Hadoop, and a custom
233
+ # application).
234
+ #
235
+ # You can use the {#images} collection to get information about
236
+ # the images available to your account. For example:
237
+ #
238
+ # ec2.images.with_owner("amazon").map(&:name)
239
+ #
240
+ # You can also use the images collection to create new images:
241
+ #
242
+ # ec2.images.create(:image_location => "mybucket/manifest.xml",
243
+ # :name => "my-image")
244
+ #
245
+ class EC2
246
+
247
+ include ServiceInterface
248
+
249
+ # @return [InstanceCollection] A collection representing all instances
250
+ def instances
251
+ InstanceCollection.new(:config => config)
252
+ end
253
+
254
+ # @return [SecurityGroupCollection] A collection representing all security
255
+ # groups.
256
+ def security_groups
257
+ SecurityGroupCollection.new(:config => config)
258
+ end
259
+
260
+ # @return [ElasticIpCollection] A collection representing all
261
+ # elastic IP addresses for this account.
262
+ def elastic_ips
263
+ ElasticIpCollection.new(:config => config)
264
+ end
265
+
266
+ # @return [KeyPairCollection] A collection representing all key pairs.
267
+ def key_pairs
268
+ KeyPairCollection.new(:config => config)
269
+ end
270
+
271
+ # @return [TagCollection] A collection representing all EC2 tags for
272
+ # all resource types.
273
+ def tags
274
+ TagCollection.new(:config => config)
275
+ end
276
+
277
+ # @return [RegionCollection] A collection representing all EC2
278
+ # regions.
279
+ def regions
280
+ RegionCollection.new(:config => config)
281
+ end
282
+
283
+ # @return [AvailabilityZoneCollection] A collection representing
284
+ # all EC2 availability zones.
285
+ def availability_zones
286
+ AvailabilityZoneCollection.new(:config => config)
287
+ end
288
+
289
+ # @return [ImageCollection] A collection representing
290
+ # all Amazon Machine Images available to your account.
291
+ def images
292
+ ImageCollection.new(:config => config)
293
+ end
294
+
295
+ # @return [VolumeCollection] A collection representing
296
+ # all EBS volumes available to your account.
297
+ def volumes
298
+ VolumeCollection.new(:config => config)
299
+ end
300
+
301
+ # @return [ReservedInstancesCollection] A collection representing all
302
+ # purchased reserved instance offerings.
303
+ def reserved_instances
304
+ ReservedInstancesCollection.new(:config => config)
305
+ end
306
+
307
+ # @return [ReservedInstancesOfferingCollection] A collection representing all
308
+ # reserved instance offerings that may be purchased.
309
+ def reserved_instances_offerings
310
+ ReservedInstancesOfferingCollection.new(:config => config)
311
+ end
312
+
313
+ # @return [SnapshotCollection] A collection representing
314
+ # all EBS snapshots available to your account.
315
+ def snapshots
316
+ SnapshotCollection.new(:config => config)
317
+ end
318
+
319
+ end
320
+
321
+ end