AWS Developer Tools Blog
Working with Regions
The AWS SDK for Ruby (aws-sdk
gem) has some cool new features that simplify working with regions.
The Ruby SDK defaults to the us-east-1
region for all services. Until recently, you had to specify the full regional endpoint for each service you connect to outside the default region. If you use multiple services outside us-east-1
, this can be a pain. Your code might end up looking like this:
AWS.config( ec2_endpoint: 'ec2.us-west-2.amazonaws.com', s3_endpoint: 's3-us-west-2.amazonaws.com', # and so on ... )
Region to the Rescue
You can now set the default region for all services with a single configuration option. Services will construct their own regional endpoint from the default region. If you want to do all of your work in us-west-2
, the example above would now look like this:
AWS.config(region: 'us-west-2')
You can pass the :region
endpoint directly to a service interface. This is helpful if you need to connect to multiple regional endpoints for a single service.
s3_east = AWS::S3.new(region: 'us-east-1') s3_west = AWS::S3.new(region: 'us-west-2')
Deprecations
The service specific endpoint options are all now deprecated. They will continue to be supported until removal in our next major revision of the Ruby SDK. The deprecated options are (replace svc
with a service prefix like ec2
, s3
, etc):
:svc_endpoint
:svc_port
:svc_region
Here are a few examples of how to upgrade from the deprecated configuration options to the new options:
# service prefixed connection options are deprecated with AWS.config AWS.config(s3_endpoint: 'localhost', s3_port: 8000) s3 = AWS::S3::Client.new # service prefixed connection options are deprecated with clients s3 = AWS::S3::Client.new(s3_endpoint: 'localhost', s3_port: 8000) # this is the preferred method for setting endpoint and port s3 = AWS::S3::Client.new(endpoint: 'localhost', port: 8000)