Configuring service clients in the Amazon SDK for Ruby - Amazon SDK for Ruby
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Configuring service clients in the Amazon SDK for Ruby

To programmatically access Amazon Web Services services, the Amazon SDK for Ruby uses a client class for each Amazon Web Services service. For example, if your application needs to access Amazon EC2, your application creates an Amazon EC2 client object to interface with that service. You then use the service client to make requests to that Amazon Web Services service.

To make a request to an Amazon Web Services service, you must first create a service client. For each Amazon Web Services service your code uses, it has its own gem and its own dedicated type for interacting with it. The client exposes one method for each API operation exposed by the service.

There are many alternative ways to configure SDK behavior, but ultimately everything has to do with the behavior of service clients. Any configuration has no effect until a service client that is created from them is used.

You must establish how your code authenticates with Amazon when you develop with Amazon Web Services services. You must also set the Amazon Web Services Region you want to use.

The Amazon SDKs and Tools Reference Guide also contains settings, features, and other foundational concepts common among many of the Amazon SDKs.

The Shared config and credentials files can be used for configuration settings. For all Amazon SDK settings, see the Settings reference in the Amazon SDKs and Tools Reference Guide.

Different profiles can be used to store different configurations. To specify the active profile that the SDK loads, you can use the AWS_PROFILE environment variable or the profile option of Aws.config.

Precedence of settings

Global settings configure features, credential providers, and other functionality that are supported by most SDKs and have a broad impact across Amazon Web Services services. All Amazon SDKs have a series of places (or sources) that they check in order to find a value for global settings. Not all settings are available in all sources. The following is the setting lookup precedence:

  1. Any explicit setting set in the code or on a service client itself takes precedence over anything else.

    1. Any parameters passed directly into a client constructor take highest precedence.

    2. Aws.config is checked for global or service-specific settings.

  2. The environment variable is checked.

  3. The shared Amazon credentials file is checked.

  4. The shared Amazon config file is checked.

  5. Any default value provided by the Amazon SDK for Ruby source code itself is used last.