Class: Dbtools::Aws
- Inherits:
-
Thor
- Object
- Thor
- Dbtools::Aws
- Defined in:
- lib/tasks/aws.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Aws
constructor
A new instance of Aws.
- #upload_to_s3(file, bucket, key) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Aws
Returns a new instance of Aws.
7 8 9 10 11 12 13 14 15 |
# File 'lib/tasks/aws.rb', line 7 def initialize(*args) super credentials_path = File.join(Dir.home, '.aws', 'credentials') if !File.exists?(credentials_path) && (ENV['AWS_ACCESS_KEY_ID'].nil? || ENV['AWS_SECRET_ACCESS_KEY'].nil?) STDERR.puts "No credentials for AWS found. You might want to configure them. " + "Your credentials should be configured in ~/.aws/credentials, or in the environmental variables ENV['AWS_ACCESS_KEY_ID'] and ENV['AWS_SECRET_ACCESS_KEY']." + "\nSee https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/ for more info. " end end |
Instance Method Details
#upload_to_s3(file, bucket, key) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/tasks/aws.rb', line 35 def upload_to_s3(file, bucket, key) client = Aws::S3::Client.new resource = Aws::S3::Resource.new(client: client) s3_bucket = resource.bucket(bucket) key = File.join([:prefix], key) if ![:prefix].nil? && ![:prefix].empty? obj = s3_bucket.object(key) obj.upload_file(file) end |