Sha256: a5d0ab5dc8aaffb8d8494918568e7a14fc0831d67207f21d361e557d3efa3b6c

Contents?: true

Size: 1.22 KB

Versions: 41

Compression:

Stored size: 1.22 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'aws/s3'

# Constants

FILE      = File.expand_path(ARGV[0])
BUCKET    = ARGV[1]
USER_DATA = `wget -q -O - http://169.254.169.254/latest/user-data`.split("\n")

# Methods

# Retrieves S3 credential information
def get_keys
   access_key = USER_DATA[0].to_s.strip
   secret_access_key = USER_DATA[1].to_s.strip
   keys = { :access_key_id => access_key,
            :secret_access_key => secret_access_key}
end #get_keys

# Establishes S3 connection
def establish_s3_connection
  @s3_connection = AWS::S3::Base.establish_connection!(get_keys)
end #establish_s3_connection

# Uploads given file to the specified S3 bucket
def upload
  # Upload the given file
  AWS::S3::S3Object.store( FILE,
                           open( FILE ),
                           BUCKET,
                           :access => :public_read )

  # display the URL of the file just uploaded
  puts AWS::S3::S3Object.url_for((FILE), BUCKET)[/[^?]+/]
end #upload

# Script

begin
  establish_s3_connection
rescue => e
  puts "Error Connecting to S3!!"
  puts e.inspect
  puts e.backtrace
  exit 1
end #begin

begin
  upload 
rescue => e
  puts "Error Uploading files!!"
  puts e.inspect
  puts e.backtrace
  exit 3
end #begin

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
rhoconnect-7.6.0 installer/utils/package_upload/s3_single_file.rb
rhoconnect-7.5.1 installer/utils/package_upload/s3_single_file.rb
rhoconnect-7.4.1 installer/utils/package_upload/s3_single_file.rb
rhoconnect-7.1.17 installer/utils/package_upload/s3_single_file.rb
rhoconnect-6.2.0 installer/utils/package_upload/s3_single_file.rb
rhoconnect-6.0.11 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.5.18 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.5.17 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.5.15 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.5.0.22 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.5.2 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.5.0.7 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.5.0.3 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.5.0 installer/utils/package_upload/s3_single_file.rb
rhoconnect-5.1.1 installer/utils/package_upload/s3_single_file.rb
rhoconnect-4.0.4 installer/utils/package_upload/s3_single_file.rb
rhoconnect-4.0.3 installer/utils/package_upload/s3_single_file.rb
rhoconnect-4.0.2 installer/utils/package_upload/s3_single_file.rb
rhoconnect-4.0.1 installer/utils/package_upload/s3_single_file.rb
rhoconnect-4.0.0 installer/utils/package_upload/s3_single_file.rb