AWS SDK for Ruby (Version 3)
repository·version-3·Indexed 25 days ago
https://github.com/aws/aws-sdk-rubyA modular, object-oriented interface for interacting with AWS services. It provides low-level API clients and high-level resource interfaces, supporting features such as automatic response paging, waiters for polling resource states, and client-side encryption for Amazon S3 via the S3 Encryption Client V3. The SDK supports Ruby >= 2.5 and allows for service-specific gem installation or a comprehensive bundle via the aws-sdk gem.
What's inside aws-sdk-ruby
- The Amazon S3 Encryption Client for Ruby receives regular updates including new API support, features, enhancements, bug fixes, security patches, and documentation updates. It is recommended to stay up-to-date with the latest releases to ensure compatibility with the latest security updates and underlying dependencies (language runtimes, operating systems, etc.).
Install the Amazon S3 Encryption Client for Ruby V3
version-3The Amazon S3 Encryption Client for Ruby V3 requires Ruby >= 2.5. You can install the SDK using Bundler by adding it to your Gemfile, or by installing theaws-sdk-s3gem directly via RubyGems.Understand AWS SDK for Ruby versioning and changelogs
version-3The AWS SDK for Ruby follows semantic versioning. You can safely depend on a major version, as minor and patch updates are guaranteed to be backwards compatible.
To view specific changes for a service, check the
CHANGELOG.mdfile located at the root of that specific gem's directory (e.g.,gems/aws-sdk-s3/CHANGELOG.md) or visit the service's page on RubyGems.org and look under the 'LINKS' section.Upgrade from AWS SDK for Ruby V2 to V3 (Recommended Service-Specific Path)
version-3The recommended way to use V3 is to install only the specific service gems your project requires. This reduces the number of dependencies in your project. You must update both your
Gemfileand yourrequirestatements in your code files.# Gemfile gem 'aws-sdk-s3', '~> 1' gem 'aws-sdk-dynamodb', '~> 1' # Code Files require 'aws-sdk-s3' require 'aws-sdk-dynamodb' s3 = Aws::S3::Client.new ddb = Aws::DynamoDB::Client.newUpgrade from aws-sdk-resources Gem to V3
version-3Users of theaws-sdk-resourcesgem can upgrade by updating the major version in theirGemfile. As with the standard path, moving to service-level gems is the recommended long-term strategy.Upgrade from aws-sdk-core Gem to V3
version-3Because
aws-sdk-corein V2 does not contain service clients, you must change yourGemfileto useaws-sdk(version 3) or specific service gems, and update yourrequirestatements accordingly.# Gemfile gem 'aws-sdk', '~> 3' # Code Files require 'aws-sdk' s3 = Aws::S3::Client.newHandle Paging Responses
version-3Many AWS operations return truncated results. The SDK provides two ways to handle paging:
Automatic Enumeration
Every AWS response object is enumerable. Calling
.eachon a response object will automatically make subsequent API calls to fetch all pages of results.Manual Paging Control
You can manually control paging using helper methods on the response object:
resp.last_page?: Returnstrueif there are no more pages.resp.next_page?: Returnstrueif another page exists.resp.next_page: Returns a new response object for the next page of results.
Upgrade AWS SDK dependencies for Library Maintainers
version-3If you maintain a library that depends on the AWS SDK, you have two upgrade options:
- Preferred Path: Switch to specific service gems (e.g.,
aws-sdk-dynamodb) to keep your library's dependency footprint small. - Simplest Path: Open the dependency range for
aws-sdkoraws-sdk-resourcesto allow V3. This is easier but adds many unnecessary gems to your users' dependency chains.
# Preferred: Gemspec File Gem::Specification.new do |spec| spec.add_dependency('aws-sdk-dynamodb', '~> 1') end # Simplest: Gemspec File Gem::Specification.new do |spec| spec.add_dependency('aws-sdk', '>= 2.0', '< 4') end- Preferred Path: Switch to specific service gems (e.g.,
Upgrade from AWS SDK for Ruby V2 to V3 (Standard Path)
version-3If your project currently uses the monolithic
aws-sdkgem, you can upgrade to V3 by updating yourGemfile. Note that this will pull in a large number of new dependencies because V3 is modularized. The modules, classes, and methods remain backwards compatible.# Gemfile gem 'aws-sdk', '~> 3'Migrate from aws-sdk-core to service-specific gems in v3.0.0
version-3In
aws-sdk-corev3.0.0, service modules were removed. Theaws-sdk-coregem now only contains shared utilities like credential providers and logging. To use specific AWS services, you must now use their dedicated gems.- If you previously used
aws-sdk-coreto access Amazon S3, replace it withaws-sdk-s3. - If you want to load all available AWS service gems at once, use the
aws-sdkgem.
- If you previously used
Configure AWS SDK credentials and region
version-3The SDK requires credentials and a region to make API calls. It searches for these in the following order of precedence:
- Client/Resource Constructor Options: Options passed directly to
Client.neworResource.new(e.g.,profile: 'my_profile') take highest precedence. Aws.configHash: Global configuration viaAws.config.updatetakes precedence over environment variables.- Environment Variables.
- Shared Configuration Files:
~/.aws/credentialsand~/.aws/config. - Instance/ECS Profiles: When running on EC2 or ECS.
Credential Locations
ENV['AWS_ACCESS_KEY_ID']andENV['AWS_SECRET_ACCESS_KEY']- Shared credentials file at
~/.aws/credentials(location configurable viaAWS_CREDENTIALS_FILE).
Region Locations
ENV['AWS_REGION']ENV['AMAZON_REGION']ENV['AWS_DEFAULT_REGION']- Shared configuration files (
~/.aws/credentialsand~/.aws/config).
Note: Shared credentials are provided statically at client creation time and do not refresh automatically.
- Client/Resource Constructor Options: Options passed directly to
Migrate to S3 Encryption Client V3
version-3The V3 library supports reading encrypted objects from previous versions with extra configuration and writing objects with non-legacy algorithms. Detailed migration paths are available for moving from V1 to V2 and V2 to V3.