Class: AWS::Core::Configuration
- Inherits:
-
Object
- Object
- AWS::Core::Configuration
- Defined in:
- lib/aws/core/configuration.rb
Overview
A configuration object for AWS interfaces and clients.
Configuring Credential
In order to do anything with AWS you will need to assign credentials. The simplest method is to assing your credentials into the default configuration:
AWS.config(:access_key_id => 'KEY', :secret_access_key => 'SECRET')
You can also export them into your environment and they will be picked up automatically:
export AWS_ACCESS_KEY_ID='YOUR_KEY_ID_HERE'
export AWS_SECRET_ACCESS_KEY='YOUR_SECRET_KEY_HERE'
For compatability with other AWS gems, the credentials can also be exported like:
export AMAZON_ACCESS_KEY_ID='YOUR_KEY_ID_HERE'
export AMAZON_SECRET_ACCESS_KEY='YOUR_SECRET_KEY_HERE'
Modifying a Configuration
Configuration objects are read-only. If you need a different set of configuration values, call #with, passing in the updates and a new configuration object will be returned.
config = Configuration.new(:max_retires => 3)
new_config = config.with(:max_retries => 2)
config.max_retries #=> 3
new_config.max_retries #=> 2
Global Configuration
The global default configuration can be found at AWS.config
Instance Attribute Summary collapse
-
#access_key_id ⇒ String?
readonly
(nil) AWS access key id credential.
-
#auto_scaling_endpoint ⇒ String
readonly
(‘autoscaling.us-east-1.amazonaws.com’) The service endpoint for Auto Scaling.
-
#cloud_formation_endpoint ⇒ String
readonly
(‘cloudformation.us-east-1.amazonaws.com’) The service endpoint for AWS CloudFormation.
-
#dynamo_db_endpoint ⇒ String
readonly
(‘dynamodb.us-east-1.amazonaws.com’) The service endpoint for Amazon DynamoDB.
-
#dynamo_db_retry_throughput_errors ⇒ String
readonly
(true) When true, AWS::DynamoDB::Errors::ProvisionedThroughputExceededException errors will be retried.
-
#ec2_endpoint ⇒ String
readonly
(‘ec2.amazonaws.com’) The service endpoint for Amazon EC2.
-
#elb_endpoint ⇒ String
readonly
(‘elasticloadbalancing.us-east-1.amazonaws.com’) The service endpoint for Elastic Load Balancing.
-
#http_handler ⇒ Object
readonly
The http handler that sends requests to AWS.
-
#iam_endpoint ⇒ String
readonly
(‘iam.amazonaws.com’) The service endpoint for AWS Idenity Access Management (IAM).
-
#log_formatter ⇒ LogFormatter
readonly
The log message formatter.
-
#log_level ⇒ Symbol
readonly
(:info) The log level.
-
#logger ⇒ Logger?
readonly
(nil) The logging interface.
-
#max_retries ⇒ Integer
readonly
(3) The maximum number of times service errors (500) should be retried.
-
#proxy_uri ⇒ String, ...
readonly
(nil) The URI of the proxy to send service requests through.
-
#s3_endpoint ⇒ String
readonly
(‘s3.amazonaws.com’) The service endpoint for Amazon S3.
-
#s3_multipart_max_parts ⇒ Integer
readonly
(1000) The maximum number of parts to split a file into when uploading in parts to S3.
-
#s3_multipart_min_part_size ⇒ Integer
readonly
(5242880) The absolute minimum size (in bytes) each S3 multipart segment should be defaults to 5242880 (5MB).
-
#s3_multipart_threshold ⇒ Integer
readonly
(16777216) When uploading data to S3, if the number of bytes to send exceedes
:s3_multipart_threshold
then a multi part session is automatically started and the data is sent up in chunks. -
#s3_server_side_encryption ⇒ Symbol
readonly
The algorithm to use when encrypting object data on the server side.
-
#secret_access_key ⇒ String?
readonly
(nil) AWS secret access key credential.
-
#session_token ⇒ String?
readonly
(nil) AWS secret token credential.
-
#signer ⇒ Object
readonly
The request signer.
-
#simple_db_consistent_reads ⇒ Boolean
readonly
(false) Determines if all SimpleDB read requests should be done consistently.
-
#simple_db_endpoint ⇒ String
readonly
(‘sdb.amazonaws.com’) The service endpoint for Amazon SimpleDB.
-
#simple_email_service_endpoint ⇒ String
readonly
(‘email.us-east-1.amazonaws.com’) The service endpoint for Amazon Simple Email Service.
-
#simple_workflow_endpoint ⇒ String
readonly
(‘swf.us-east-1.amazonaws.com’) The service endpoint for Amazon Simple Workflow Service.
-
#sns_endpoint ⇒ String
readonly
(‘sns.us-east-1.amazonaws.com’) The service endpoint for Amazon SNS.
-
#sqs_endpoint ⇒ String
readonly
(‘sqs.us-east-1.amazonaws.com’) The service endpoint for Amazon SQS.
-
#ssl_ca_file ⇒ String
readonly
The path to a CA cert bundle in PEM format.
-
#ssl_ca_path ⇒ String
readonly
(nil) The path the a CA cert directory.
-
#ssl_verify_peer ⇒ Boolean
readonly
(true) When
true
the HTTP handler validate server certificates for HTTPS requests. -
#sts_endpoint ⇒ String
readonly
(‘sts.amazonaws.com’) The service endpoint for AWS Security Token Service.
-
#stub_requests ⇒ Boolean
readonly
(false) When
true
requests are not sent to AWS, instead empty reponses are generated and returned to each service request. -
#use_ssl ⇒ Boolean
readonly
(true) When
true
, all requests to AWS are sent using HTTPS instead vanilla HTTP. -
#user_agent_prefix ⇒ String
readonly
(nil) A string prefix to append to all requets against AWS services.
Class Method Summary collapse
- .accepted_options ⇒ Object
- .add_option(name, default_value = nil, options = {}, &transform) ⇒ Object
-
.add_option_with_needs(name, needs, &create_block) ⇒ Object
Configuration options that have dependencies are re-recreated anytime one of their dependendent configuration values are changed.
- .add_service(name, ruby_name, default_endpoint) ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql)
Returns true if the two configuration objects have the same values.
-
#credentials ⇒ Hash
Returns a hash with your configured credentials.
-
#initialize(options = {}) ⇒ Configuration
constructor
Creates a new Configuration object.
- #inspect ⇒ Object
-
#to_h ⇒ Hash
Returns a hash of all configuration values.
-
#with(options = {}) ⇒ Configuration
Used to create a new Configuration object with the given modifications.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Creates a new Configuration object.
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/aws/core/configuration.rb', line 206 def initialize = {} @created = .delete(:__created__) || {} .each_pair do |opt_name, value| opt_name = opt_name.to_sym if self.class..include?(opt_name) supplied[opt_name] = value end end end |
Instance Attribute Details
#access_key_id ⇒ String? (readonly)
(nil) AWS access key id credential.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def access_key_id @access_key_id end |
#auto_scaling_endpoint ⇒ String (readonly)
(‘autoscaling.us-east-1.amazonaws.com’) The service endpoint for Auto Scaling.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def auto_scaling_endpoint @auto_scaling_endpoint end |
#cloud_formation_endpoint ⇒ String (readonly)
(‘cloudformation.us-east-1.amazonaws.com’) The service endpoint for AWS CloudFormation.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def cloud_formation_endpoint @cloud_formation_endpoint end |
#dynamo_db_endpoint ⇒ String (readonly)
(‘dynamodb.us-east-1.amazonaws.com’) The service endpoint for Amazon DynamoDB.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def dynamo_db_endpoint @dynamo_db_endpoint end |
#dynamo_db_retry_throughput_errors ⇒ String (readonly)
(true) When true, AWS::DynamoDB::Errors::ProvisionedThroughputExceededException errors will be retried.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def dynamo_db_retry_throughput_errors @dynamo_db_retry_throughput_errors end |
#ec2_endpoint ⇒ String (readonly)
(‘ec2.amazonaws.com’) The service endpoint for Amazon EC2.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def ec2_endpoint @ec2_endpoint end |
#elb_endpoint ⇒ String (readonly)
(‘elasticloadbalancing.us-east-1.amazonaws.com’) The service endpoint for Elastic Load Balancing.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def elb_endpoint @elb_endpoint end |
#http_handler ⇒ Object (readonly)
The http handler that sends requests to AWS. Defaults to an HTTP handler built on net/http.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def http_handler @http_handler end |
#iam_endpoint ⇒ String (readonly)
(‘iam.amazonaws.com’) The service endpoint for AWS Idenity Access Management (IAM).
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def iam_endpoint @iam_endpoint end |
#log_formatter ⇒ LogFormatter (readonly)
The log message formatter.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def log_formatter @log_formatter end |
#log_level ⇒ Symbol (readonly)
(:info) The log level.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def log_level @log_level end |
#logger ⇒ Logger? (readonly)
(nil) The logging interface.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def logger @logger end |
#max_retries ⇒ Integer (readonly)
(3) The maximum number of times service errors (500) should be retried. There is an exponential backoff in between service request retries, so the more retries the longer it can take to fail.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def max_retries @max_retries end |
#proxy_uri ⇒ String, ... (readonly)
(nil) The URI of the proxy to send service requests through. You can pass a URI object or a URI string. Defautls to nil
.
AWS.config(:proxy_uri => 'https://user:[email protected]:443')
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def proxy_uri @proxy_uri end |
#s3_endpoint ⇒ String (readonly)
(‘s3.amazonaws.com’) The service endpoint for Amazon S3.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def s3_endpoint @s3_endpoint end |
#s3_multipart_max_parts ⇒ Integer (readonly)
(1000) The maximum number of parts to split a file into when uploading in parts to S3.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def s3_multipart_max_parts @s3_multipart_max_parts end |
#s3_multipart_min_part_size ⇒ Integer (readonly)
(5242880) The absolute minimum size (in bytes) each S3 multipart segment should be defaults to 5242880 (5MB).
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def s3_multipart_min_part_size @s3_multipart_min_part_size end |
#s3_multipart_threshold ⇒ Integer (readonly)
(16777216) When uploading data to S3, if the number of bytes to send exceedes :s3_multipart_threshold
then a multi part session is automatically started and the data is sent up in chunks. The size of each part is specified by :s3_multipart_min_part_size
. Defaults to 16777216 (16MB).
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def s3_multipart_threshold @s3_multipart_threshold end |
#s3_server_side_encryption ⇒ Symbol (readonly)
The algorithm to use when encrypting object data on the server side. The only valid value is :aes256
, which specifies that the object should be stored using the AES encryption algorithm with 256 bit keys. Defaults to nil
, meaning server side encryption is not used unless specified on each individual call to upload an object. This option controls the default behavior for the following method:
You can construct an interface to Amazon S3 which always stores data using server side encryption as follows:
s3 = AWS::S3.new(:s3_server_side_encryption => :aes256)
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def s3_server_side_encryption @s3_server_side_encryption end |
#secret_access_key ⇒ String? (readonly)
(nil) AWS secret access key credential.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def secret_access_key @secret_access_key end |
#session_token ⇒ String? (readonly)
(nil) AWS secret token credential.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def session_token @session_token end |
#signer ⇒ Object (readonly)
The request signer. Defaults to a default request signer implementation.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def signer @signer end |
#simple_db_consistent_reads ⇒ Boolean (readonly)
(false) Determines if all SimpleDB read requests should be done consistently. Consistent reads are slower, but reflect all changes to SDB.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def simple_db_consistent_reads @simple_db_consistent_reads end |
#simple_db_endpoint ⇒ String (readonly)
(‘sdb.amazonaws.com’) The service endpoint for Amazon SimpleDB.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def simple_db_endpoint @simple_db_endpoint end |
#simple_email_service_endpoint ⇒ String (readonly)
(‘email.us-east-1.amazonaws.com’) The service endpoint for Amazon Simple Email Service.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def simple_email_service_endpoint @simple_email_service_endpoint end |
#simple_workflow_endpoint ⇒ String (readonly)
(‘swf.us-east-1.amazonaws.com’) The service endpoint for Amazon Simple Workflow Service.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def simple_workflow_endpoint @simple_workflow_endpoint end |
#sns_endpoint ⇒ String (readonly)
(‘sns.us-east-1.amazonaws.com’) The service endpoint for Amazon SNS.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def sns_endpoint @sns_endpoint end |
#sqs_endpoint ⇒ String (readonly)
(‘sqs.us-east-1.amazonaws.com’) The service endpoint for Amazon SQS.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def sqs_endpoint @sqs_endpoint end |
#ssl_ca_file ⇒ String (readonly)
The path to a CA cert bundle in PEM format.
If ssl_verify_peer
is true (the default) this bundle will be used to validate the server certificate in each HTTPS request. The AWS SDK for Ruby ships with a CA cert bundle, which is the default value for this option.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def ssl_ca_file @ssl_ca_file end |
#ssl_ca_path ⇒ String (readonly)
(nil) The path the a CA cert directory.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def ssl_ca_path @ssl_ca_path end |
#ssl_verify_peer ⇒ Boolean (readonly)
(true) When true
the HTTP handler validate server certificates for HTTPS requests.
This option should only be disabled for diagnostic purposes; leaving this option set to false
exposes your application to man-in-the-middle attacks and can pose a serious security risk.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def ssl_verify_peer @ssl_verify_peer end |
#sts_endpoint ⇒ String (readonly)
(‘sts.amazonaws.com’) The service endpoint for AWS Security Token Service.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def sts_endpoint @sts_endpoint end |
#stub_requests ⇒ Boolean (readonly)
(false) When true
requests are not sent to AWS, instead empty reponses are generated and returned to each service request.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def stub_requests @stub_requests end |
#use_ssl ⇒ Boolean (readonly)
(true) When true
, all requests to AWS are sent using HTTPS instead vanilla HTTP.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def use_ssl @use_ssl end |
#user_agent_prefix ⇒ String (readonly)
(nil) A string prefix to append to all requets against AWS services. This should be set for clients and applications built ontop of the aws-sdk gem.
201 202 203 |
# File 'lib/aws/core/configuration.rb', line 201 def user_agent_prefix @user_agent_prefix end |
Class Method Details
.accepted_options ⇒ Object
292 293 294 |
# File 'lib/aws/core/configuration.rb', line 292 def @options ||= Set.new end |
.add_option(name, default_value = nil, options = {}, &transform) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/aws/core/configuration.rb', line 297 def add_option name, default_value = nil, = {}, &transform << name define_method(name) do |&default_override| value = if supplied.has_key?(name) supplied[name] elsif default_override default_override.call else default_value end transform ? transform.call(self, value) : value end alias_method("#{name}?", name) if [:boolean] end |
.add_option_with_needs(name, needs, &create_block) ⇒ Object
Configuration options that have dependencies are re-recreated anytime one of their dependendent configuration values are changed.
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/aws/core/configuration.rb', line 324 def add_option_with_needs name, needs, &create_block << name define_method(name) do return supplied[name] if supplied.has_key?(name) needed = needs.collect{|need| send(need) } unless @created.key?(name) and @created[name][:needed] == needed @created[name] = {} @created[name][:object] = create_block.call(self) @created[name][:needed] = needed end @created[name][:object] end end |
.add_service(name, ruby_name, default_endpoint) ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/aws/core/configuration.rb', line 346 def add_service name, ruby_name, default_endpoint add_option :"#{ruby_name}_endpoint", default_endpoint add_option(:"#{ruby_name}_port") do |config,value| value || (config.use_ssl? ? 443 : 80) end # users only need to specify service regions when they use # a test endpoint with a sigv4 service add_option(:"#{ruby_name}_region") do |config,value| value || begin endpoint = config.send("#{ruby_name}_endpoint") if endpoint =~ /us-gov/ if matches = endpoint.match(/(us-gov-west-\d+)/) matches[1] else 'us-gov-west-1' # e.g. iam.us-gov.amazonaws.com end elsif matches = endpoint.match(/^.+\.(.+)\.amazonaws.com$/) matches[1] else 'us-east-1' end end end needs = [ :signer, :http_handler, :"#{ruby_name}_endpoint", :"#{ruby_name}_port", :max_retries, :stub_requests?, :proxy_uri, :use_ssl?, :ssl_verify_peer?, :ssl_ca_file, :user_agent_prefix, :logger, :log_formatter, :log_level, ] create_block = lambda do |config| AWS.const_get(name)::Client.new(:config => config) end add_option_with_needs :"#{ruby_name}_client", needs, &create_block end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql
Returns true if the two configuration objects have the same values.
273 274 275 |
# File 'lib/aws/core/configuration.rb', line 273 def == other other.is_a?(self.class) and self.supplied == other.supplied end |
#credentials ⇒ Hash
Returns a hash with your configured credentials.
220 221 222 223 224 225 226 |
# File 'lib/aws/core/configuration.rb', line 220 def credentials credentials = {} credentials[:access_key_id] = access_key_id credentials[:secret_access_key] = secret_access_key credentials[:session_token] = session_token if session_token credentials end |
#inspect ⇒ Object
280 281 282 |
# File 'lib/aws/core/configuration.rb', line 280 def inspect "<#{self.class.name}>" end |
#to_h ⇒ Hash
Returns a hash of all configuration values.
264 265 266 267 268 269 |
# File 'lib/aws/core/configuration.rb', line 264 def to_h self.class..inject({}) do |h,k| h[k] = send(k) h end end |
#with(options = {}) ⇒ Configuration
Used to create a new Configuration object with the given modifications. The current configuration object is not modified.
AWS.config(:max_retries => 2)
no_retries_config = AWS.config.with(:max_retries => 0)
AWS.config.max_retries #=> 2
no_retries_config.max_retries #=> 0
You can use these configuration objects returned by #with to create AWS objects:
AWS::S3.new(:config => no_retries_config)
AWS::SQS.new(:config => no_retries_config)
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/aws/core/configuration.rb', line 248 def with = {} # symbolize option keys = .inject({}) {|h,kv| h[kv.first.to_sym] = kv.last; h } values = supplied.merge() if supplied == values self # nothing changed else self.class.new(values.merge(:__created__ => @created.dup)) end end |