Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

AWS SDK for Ruby code examples for Amazon S3

Purpose

This folder contains code examples that demonstrate how to use the AWS SDK for Ruby to automate Amazon Simple Storage Service (Amazon S3).

Prerequisites

  • An AWS account. To create an account, see How do I create and activate a new AWS account on the AWS Premium Support website.
  • AWS credentials or an AWS Security Token Service (AWS STS) access token. For details, see Configuring the AWS SDK for Ruby in the AWS SDK for Ruby Developer Guide.
  • To run the code examples, Ruby version 1.9 or later. For Ruby download and installation instructions, see Download Ruby on the Ruby Progamming Language website.
  • To test the code examples, RSpec 3.9 or later. For RSpec download and installation instructions, see the rspec/rspec repository in GitHub.
  • The AWS SDK for Ruby. For AWS SDK for Ruby download and installation instructions, see Install the AWS SDK for Ruby in the AWS SDK for Ruby Developer Guide.

Cautions

  • As an AWS best practice, grant this code least privilege, or only the permissions required to perform a task. For more information, see Grant least privilege in the AWS Identity and Access Management User Guide.
  • This code has not been tested in all AWS Regions. Some AWS services are available only in specific AWS Regions. For more information, see the AWS Regional Services List on the AWS website.
  • Running this code might result in charges to your AWS account.

Running the code

Most of these code example files can be run with very little to no modification. For example, to use Ruby to run the create_bucket_snippet.rb file, replace the hard-coded bucket_name and region variable values in the file with your own values, save the file, and then run the file. For example:

ruby create_bucket_snippet.rb

Most of these files have been refactored into reusable functions that can be copied into your own code. You can then call those functions directly from your own code without modifying the copied function code itself. For example, you could copy the bucket_created? function code from the create_bucket_snippet.rb file into your own code. You could then adapt the code in the run_me function in that same file as a basis to write your own code to call the copied bucket_created? function.

Running the tests

Most of these code example files have accompanying tests that are written to work with RSpec. These tests are in the tests folder and contain the same file name as the corresponding code example file, for example tests/test_create_bucket_snippet.rb contains tests for create_bucket_snippet.rb.

To use RSpec to run all tests within a file, specify the path to that file, for example:

rspec tests/test_create_bucket_snippet.rb

To explore additional options for using RSpec to run tests, run the rspec --help command.

Most of these tests are designed to use stubs, to avoid generating unnecessary costs in an AWS account. For more information, see Stubbing Client Responses and Errors in the AWS SDK for Ruby Developer Guide.

Additional information


Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0