
• https://github.com/aws/aws-sdk-ruby/archive/master.zip
2. Unzip it into a local directory.
3. Open a terminal window and change to the directory where you unzipped the source archive.
The samples are in the samples directory in the SDK for Ruby source.You can view the samples by
listing this directory:
ls samples
Note
On Windows, use the dir command instead.
Set your AWS Credentials
Because these are AWS SDK for Ruby samples, you will need to provide AWS credentials so that they
can communicate with AWS.
The samples generally use the default credential provider chain (p. 6) to load credentials. The easiest
way to set your credentials so that they can be loaded by the default provider chain is to set the environment
variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
For more information about how to set credentials for use with the SDK, including alternate ways to set
credentials, see Setting up AWS Credentials (p. 5).
Run the Samples
Once you have downloaded the samples and have your credentials set, you can run the samples to see
how they interact with AWS. We'll demonstrate using the upload_file.rb sample, located in the
aws-sdk-ruby/samples/s3 directory.
To run the upload_file sample
1. Open a terminal window and change to the samples/s3 directory containing the upload_file.rb
sample. For example, if you put the SDK for Ruby source in ~/source/aws-sdk-ruby, then type:
cd ~/source/aws-sdk-ruby/samples/s3
2. The upload_file.rb script requires a file to upload to S3. Copy any test file you like to the current
directory. For example, if you have a test file called test.png in your Pictures directory, you would
type:
cp ~/Pictures/test.png .
3. Run the upload_file.rb script with Ruby, providing it with an S3 bucket name (the bucket will be
created if it doesn't already exist) and the name of the file you want to upload. For example:
ruby upload_file.rb my_test_bucket test.png
Version v1.0.0
22
AWS SDK for Ruby Developer Guide
Set your AWS Credentials
Comentarios a estos manuales