
:credential_provider => AWS::Core::CredentialProviders::SharedCredentialFile
Provider.new)
Creating the provider object with the default constructor specifies the credentials file's default profile.
You can also use the constructor's profile_name option to specify a profile by name or its path option
to specify a nondefault credentials file location.
• You can specify a credential provider that will be used by all service clients by passing a provider object
to the AWS.config method. The following example specifies the default profile from the credentials file
for all services.
AWS.config(
:credential_provider => AWS::Core::CredentialProviders::SharedCredentialFile
Provider.new)
# Create a new S3 object
s3 = AWS::S3.new
You can then use the Amazon S3 client object's default constructor, which automatically loads the ap-
propriate profile.
For the full list of SDK for Ruby credential provider classes, see AWS::Core::CredentialProviders. In the
SDK for Ruby, all provider classes mix in the Provider interface.
Tip
You can also use this approach to supply your own credentials provider. Just implement a cre-
dentials provider class that mixes in the Provider interface.You can then pass an instance of
the class to a service's client class constructor or to AWS.config, as described above.
Explicitly Specifying Credentials
You can specify credentials explicitly as follows.
• Specify credentials for a particular service by using the client class constructor's :access_key_id
and :secret_access_key options.
The following example specifies an explicit set of credentials for the Amazon S3 client object.
s3 = AWS::S3.new(
:access_key_id => 'AKIAIOSFODNN7EXAMPLE',
:secret_access_key => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY')
• Specify credentials for every service by using the AWS.config method's :access_key_id and
:secret_access_key options.
The following example specifies an explicit set of credentials for every service, so you can use the default
constructor to create the Amazon S3 client object. It will automatically use the credentials that you
passed to AWS.config.
AWS.config(
:access_key_id => 'AKIAIOSFODNN7EXAMPLE',
:secret_access_key => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY')
Version v1.0.0
7
AWS SDK for Ruby Developer Guide
Explicitly Specifying Credentials
Komentarze do niniejszej Instrukcji