
permissions, as shown in Using IAM Roles for Amazon EC2 Instances with the AWS SDK for
Ruby (p. 9).
The AWS SDKs and CLIs use a provider chain to look for default AWS credentials, or you can specify
the appropriate credentials explicitly. For more information, see Specifying Credentials (p. 6).
Specifying AWS Credentials for SDK for Ruby
Applications
Note
This documentation is for the AWS SDK for Ruby version 1, which is a legacy version. For the
most recent version of the SDK for Ruby, see AWS SDK for Ruby - Version 2.
For an SDK for Ruby application to access Amazon Web Services, you must provide the application with
a set AWS credentials that have appropriate permissions.You specify which credentials your application
will use to access a service when you initialize a new service client. This topic describes how to specify
AWS credentials for SDK for Ruby applications.
Topics
• Using Default Credentials (p. 6)
• Specifying a Credentials Provider (p. 7)
• Explicitly Specifying Credentials (p. 7)
Using Default Credentials
One option is to create the client without any arguments, as shown in the following example.
# Create a new S3 object
s3 = AWS::S3.new
In this case, the SDK for Ruby attempts to use your default AWS credentials to create the client object.
It locates them by using the default credential provider chain, which is implemented by the DefaultProvider
class. It looks for default credentials in the following order and loads the first set that it finds:
1. Credentials passed to the AWS.config method with the :access_key_id and
:secret_access_key_id options.
2. Environment Variables – AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment
variables.
The SDK for Ruby uses the ENVProvider class to load these credentials.
3. The credentials file's default profile – For more information about the credentials file, see Setting
up AWS Credentials (p. 5).
The SDK for Ruby uses the SharedCredentialFileProvider to load profiles.
4. Instance profile credentials – these credentials can be assigned to Amazon EC2 instances, and are
delivered through the Amazon EC2 metadata service.
The SDK for Ruby uses EC2Provider to load these credentials.
Version v1.0.0
6
AWS SDK for Ruby Developer Guide
Specifying Credentials
Komentáře k této Příručce