refile / refile-s3

Amazon S3 Backend for Refile
MIT License
36 stars 88 forks source link

make aws keys optional (for use IAM S3 role) #2

Closed artempartos closed 9 years ago

artempartos commented 9 years ago

close #1

# config/initializers/refile.rb
require "refile/s3"
aws = {
  region: "sa-east-1",
  bucket: "my-bucket",
}

Refile.cache = Refile::S3.new(prefix: "cache", **aws)
Refile.store = Refile::S3.new(prefix: "store", **aws)
# config/initializers/refile.rb
require "refile/s3"

aws = {
  access_key_id: "xyz",
  secret_access_key: "abc",
  region: "sa-east-1",
  bucket: "my-bucket",
}
Refile.cache = Refile::S3.new(prefix: "cache", **aws)
Refile.store = Refile::S3.new(prefix: "store", **aws)
jnicklas commented 9 years ago

Nice! Thank you!

fredkelly commented 8 years ago

I'm trying to use IAM roles but passing just region and bucket is giving me the following error:

DEPRECATION WARNING: called deprecated method `access_key_id' of an Aws::CredentialProvider, use #credentials instead

(I'm sourcing the gem from github to get this PR).

I've seen the discussion in #18 but my configuration appears to be correct:

# config/initializers/refile.rb
require 'refile/s3'

if Rails.env.production?
  aws = {
    region: ENV['AWS_REGION'],
    bucket: ENV['ATTACHMENT_BUCKET']
  }

  Refile.cache = Refile::S3.new(prefix: 'cache', max_size: 10.megabytes, **aws)
  Refile.store = Refile::S3.new(prefix: 'store', **aws)
end
# config/initializers/aws.rb
if Rails.env.production?
  Aws.config.update({
    region: ENV['AWS_REGION'],
    credentials: Aws::InstanceProfileCredentials.new()
  })
end

Edited: copied the wrong error.