AWS SDK for Ruby (Version 3)

repository·version-3·Indexed 25 days ago

https://github.com/aws/aws-sdk-ruby

A 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.

Tokens
38.4K
Snippets
134
Records
184
Agent score
87%

What's inside aws-sdk-ruby

  1. Understand the Amazon S3 Encryption Client for Ruby support policy

    version-3
    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.).
  2. Understand AWS SDK for Ruby versioning and changelogs

    version-3

    The 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.md file 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.

  3. Upgrade from AWS SDK for Ruby V2 to V3 (Recommended Service-Specific Path)

    version-3

    The 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 Gemfile and your require statements 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.new
  4. Upgrade from aws-sdk-core Gem to V3

    version-3

    Because aws-sdk-core in V2 does not contain service clients, you must change your Gemfile to use aws-sdk (version 3) or specific service gems, and update your require statements accordingly.

    # Gemfile
    gem 'aws-sdk', '~> 3'
    
    # Code Files
    require 'aws-sdk'
    
    s3 = Aws::S3::Client.new
  5. Handle Paging Responses

    version-3

    Many AWS operations return truncated results. The SDK provides two ways to handle paging:

    Automatic Enumeration

    Every AWS response object is enumerable. Calling .each on 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?: Returns true if there are no more pages.
    • resp.next_page?: Returns true if another page exists.
    • resp.next_page: Returns a new response object for the next page of results.
  6. Upgrade AWS SDK dependencies for Library Maintainers

    version-3

    If you maintain a library that depends on the AWS SDK, you have two upgrade options:

    1. Preferred Path: Switch to specific service gems (e.g., aws-sdk-dynamodb) to keep your library's dependency footprint small.
    2. Simplest Path: Open the dependency range for aws-sdk or aws-sdk-resources to 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
  7. Upgrade from AWS SDK for Ruby V2 to V3 (Standard Path)

    version-3

    If your project currently uses the monolithic aws-sdk gem, you can upgrade to V3 by updating your Gemfile. 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'
  8. Migrate from aws-sdk-core to service-specific gems in v3.0.0

    version-3

    In aws-sdk-core v3.0.0, service modules were removed. The aws-sdk-core gem 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-core to access Amazon S3, replace it with aws-sdk-s3.
    • If you want to load all available AWS service gems at once, use the aws-sdk gem.
  9. Configure AWS SDK credentials and region

    version-3

    The SDK requires credentials and a region to make API calls. It searches for these in the following order of precedence:

    1. Client/Resource Constructor Options: Options passed directly to Client.new or Resource.new (e.g., profile: 'my_profile') take highest precedence.
    2. Aws.config Hash: Global configuration via Aws.config.update takes precedence over environment variables.
    3. Environment Variables.
    4. Shared Configuration Files: ~/.aws/credentials and ~/.aws/config.
    5. Instance/ECS Profiles: When running on EC2 or ECS.

    Credential Locations

    • ENV['AWS_ACCESS_KEY_ID'] and ENV['AWS_SECRET_ACCESS_KEY']
    • Shared credentials file at ~/.aws/credentials (location configurable via AWS_CREDENTIALS_FILE).

    Region Locations

    • ENV['AWS_REGION']
    • ENV['AMAZON_REGION']
    • ENV['AWS_DEFAULT_REGION']
    • Shared configuration files (~/.aws/credentials and ~/.aws/config).

    Note: Shared credentials are provided statically at client creation time and do not refresh automatically.