New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS::S3::Errors::PermanentRedirect #163

Closed
swilson224 opened this Issue May 19, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@swilson224

swilson224 commented May 19, 2017

Hey I am using Shrine Gem with Rails 5.0.3 and ruby 2.4.0

When I attempt to upload a file I get the following message in my console and the upload fails.

"The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint"

now after reading some AWS Docs and stackoverflow questions / issues, the solution seems to be adding s3_host_name to the config.

When I try to do this, shrine fails saying that its an invalid attribute.

Do you guys have a workaround for this?

@swilson224

This comment has been minimized.

swilson224 commented May 19, 2017

so I sorted this out,

I changed up my shrine.rb file to look like so

require "shrine/storage/s3"

s3_options = {
    access_key_id: ENV["AWS_ACCESS_KEY_ID"],
    secret_access_key: ENV["AWS_SECRET_KEY"],
    region: ENV["AWS_REGION"],
    bucket: ENV["AWS_BUCKET"],
    endpoint: ENV["AWS_HOST"],
}

Shrine.storages = {
    cache: Shrine::Storage::S3.new(prefix: "cache", **s3_options),
    store: Shrine::Storage::S3.new(prefix: "store", **s3_options),
}

Shrine.plugin :activerecord
Shrine.plugin :direct_upload
Shrine.plugin :restore_cached_data

Perhaps you could update the documentation to reflect this for more novice Shrine users. ?

@swilson224 swilson224 closed this May 19, 2017

@janko-m

This comment has been minimized.

Member

janko-m commented May 21, 2017

I will reopen this issue, as I still want to figure out what changed, and make the appropriate patch in Shrine if necessary (because the extra :endpoint parameter seems redundant). Could you post your aws-sdk gem version, and what region are you using?

@janko-m janko-m reopened this May 21, 2017

@janko-m

This comment has been minimized.

Member

janko-m commented May 21, 2017

@swilson224 Also, it would be very useful to find out what endpoint this aws-sdk generate by default, when you don't pass it the :endpoint option. If you can, please let me know the output of the following script for you, and what did you put in the AWS_HOST env variable to fix the issue.

require "aws-sdk"

resource = Aws::S3::Resource.new(
  access_key_id: "abc",
  secret_access_key: "xyz",
  region: "ca-central-1",
)

bucket = resource.bucket("my-bucket")
object = bucket.object("key")

puts object.presigned_url(:get) # you can omit the query parameters for security
puts object.public_url
@janko-m

This comment has been minimized.

Member

janko-m commented May 22, 2017

I cannot reproduce it, but the issue might be caused by a combination of the following:

  • Your bucket name has dots in it (in which case the aws-sdk switches to the path-style URL instead of having the bucket name in the hostname)
  • Your bucket resides in a different region than ca-central-1

Since I'm not able to reproduce the issue, I will close this. If there is an actual bug, it should probably be solved inside the aws-sdk gem.

@janko-m janko-m closed this May 22, 2017

@swilson224

This comment has been minimized.

swilson224 commented May 26, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment