AWS Code Sample


auth_request_object_keys.rb uses the credentials in a shared AWS credentials file on a local computer to authenticate a request to get all of the object key names in a specific bucket.

#** #* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. #* #* This file is licensed under the Apache License, Version 2.0 (the "License"). #* You may not use this file except in compliance with the License. A copy of #* the License is located at #* #* #* #* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR #* CONDITIONS OF ANY KIND, either express or implied. See the License for the #* specific language governing permissions and limitations under the License. #** # This snippet example does the following: # Creates an instance of the Aws::S3::Resource class. # Makes a request to Amazon S3 by enumerating objects in a bucket using the bucket method of Aws::S3::Resource. # The client generates the necessary signature value from the credentials in the AWS credentials file on your computer, # and includes it in the request it sends to Amazon S3. # Prints the array of object key names to the terminal. # The credentials that are used for this example come from a local AWS credentials file on the computer that is running this application. # The credentials are for an IAM user who can list objects in the bucket that the user specifies when they run the application. # Use the Amazon S3 modularized gem for version 3 of the AWS Ruby SDK. require 'aws-sdk-s3' # Get an Amazon S3 resource. s3 = 'us-west-2') # Create an array of up to the first 100 object keynames in the bucket. bucket = s3.bucket('example_bucket').objects.collect(&:key) # Print the array to the terminal. puts bucket

Sample Details

Service: s3

Last tested: 2019-01-28

Author: AWS

Type: full-example

On this page: