Amazon AWS SDK Manual de usuario Pagina 9

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 28
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 8
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. 6)
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_ac-
cess_key_id options.
2. Environment VariablesAWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment vari-
ables.
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. 4).
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.
Note
You must have specified default credentials in at least one of these ways, or the attempt will fail.
For more information, see Setting up AWS Credentials (p. 4).
Specifying a Credentials Provider
If you don't want to use the default credentials provider, you can specify your preferred credentials provider.
For example, you might want to use a nondefault profile from the credentials file, which is handled by
SharedCredentialFileProvider.You can specify a credentials provider as follows:
To specify a credentials provider for a particular service, pass a provider object to the service's client
constructor, which must take a class with the Provider interface as input. A provider typically has options
that you can use to specify a particular set of credentials.
The following example directs the Amazon S3 client constructor to get its credentials from the
SharedCredentialFileProvider object, which loads credentials from the credentials file.
# Create a new S3 object using a specific provider
s3 = AWS::S3.new(
Version v1.0.0
6
AWS SDK for Ruby Developer Guide
Using Default Credentials
Vista de pagina 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... 27 28

Comentarios a estos manuales

Sin comentarios