Skip to content
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

301 Redirect error #26

Closed
joshhunt opened this issue Jul 27, 2014 · 12 comments
Closed

301 Redirect error #26

joshhunt opened this issue Jul 27, 2014 · 12 comments

Comments

@joshhunt
Copy link

Whenever I use this, I keep getting the following error:

$ gulp publish
[19:42:26] Requiring external module coffee-script/register
[19:42:27] Using gulpfile ~/Development/gifs/Gulpfile.coffee
[19:42:27] Starting 'publish'...

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: HTTP 301 Response returned from S3

Here's my task so far

gulp.task 'publish', ->
    publisher = awspublish.create { key: env.S3_KEY,  secret: env.S3_SECRET, bucket: env.S3_BUCKET }
    headers = {'Cache-Control': 'max-age=315360000, no-transform, public'}

    gulp.src "#{OUTPUT}/**/*"
        .pipe awspublish.gzip {'ext': '.gz'}
        .pipe publisher.publish headers
        .pipe publisher.cache()
        .pipe awspublish.reporter()

And my env variables:

S3_BUCKET=gifs.joshhunt.is
S3_KEY=...
S3_SECRET=...

What would be causing this? Should gulp-awspublish/knox follow the redirect, or have I made an error somewhere?

Edit: Digging in some more, if I make a get request, I get this back:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>PermanentRedirect</Code>
    <Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message>
    <RequestId>...</RequestId>
    <Bucket>gifs.joshhunt.is</Bucket>
    <HostId>...</HostId>
    <Endpoint>gifs.joshhunt.is.s3.amazonaws.com</Endpoint>
</Error>
@joshhunt
Copy link
Author

Changing my bucket ID to one without periods fixed the issue, but I guess this one is worth looking into...

@pgherveou
Copy link
Owner

I use it with buckets with period,
checkout knox the module we suse to talk to s3
https://github.com/LearnBoost/knox#style

On Sun, Jul 27, 2014 at 11:54 AM, Josh Hunt [email protected]
wrote:

Changing my bucket ID to one without periods fixed the issue, but I guess
this one is worth looking into...


Reply to this email directly or view it on GitHub
#26 (comment)
.

PG

@shedd
Copy link

shedd commented Feb 6, 2015

I also ran into this issue after changing my S3 bucket name. At first, I also suspected that it was a bucket name with periods, but it turned out that I moved from a US Standard bucket to one in US West and needed to specify the region attribute: https://github.com/LearnBoost/knox#region

@dknochen
Copy link

I had the same error on some machines and didn't have it on others. In the end, I narrowed the error down to the following conditions:

  • the bucket name contains periods
  • protocol is https (secure: true)
  • publish was called from an ec2 machine

the workaround in my case:

  • add config.secure = false; (i.e. use http instead of https which is no problem in my case because requests stay within the AWS network ec2->s3):
awspublish.create({
     key: key,
     secret: secret,
     bucket: bucketName,
     secure: false
});

As HTTP 301 is not really an error, I would expect awspublish to just follow the redirect?

There is a related discussion on the knox repo: Automattic/knox#66

@pgherveou
Copy link
Owner

The current version of the plugin use the aws sdk so this might be outdated
as long as you can use the aws sdk and push files to S3 with it, this plugin should work too

@gon
Copy link

gon commented Apr 12, 2015

@shedd is right, even though S3's Region pulldown menu seems not to care about Regions it so does. My suggestion is to always specify the region option, e.g.

awspublish.create({
     key: key,
     secret: secret,
     bucket: "www.awesome.com",
     region: "us-west-1"
});

(secure: false wasn't it for me)

@pgherveou
Copy link
Owner

Yep you are right could you add a note inside the readme maybe?

@panmanphil
Copy link

With the current 2.0.2 version of the plugin, using a name with periods in it, required for host name mapping of an s3 bucket, a publish command fails with the 301 issue. I can use the exact same code with a bucket without a period and all is fine. I am specifying the region as shown above. I can post with the aws s3 command with no problems.

Any suggestions would be appreciated.

@pgherveou
Copy link
Owner

See if this thread helps
#53

Check if you can do the following operations that the plugin does with your AWS client
https://github.com/pgherveou/gulp-awspublish/blob/master/lib/index.js#L312
https://github.com/pgherveou/gulp-awspublish/blob/master/lib/index.js#L336

@panmanphil
Copy link

Gah! yes region was still the problem. I had region in there, but in the wrong place. It would really be great if the example on the README.md just had this in it from the start.

instead of:

  var publisher = awspublish.create({
    params: {
      Bucket: '...'
    }
  });

please update the README to say

  var publisher = awspublish.create({
   region: 'us-west-2',
    params: {
      Bucket: '...'
    }
  });

But thanks for the quick comment I have it working now.

@pgherveou
Copy link
Owner

Cool glad it worked for u, can u send me a pull request to the readme

Sent from my iPhone

On Nov 22, 2015, at 8:07 PM, Philip Nelson [email protected] wrote:

Gah! yes region was still the problem. I had region in there, but in the wrong place. It would really be great if the example on the README.md just had this in it from the start.

instead of:

var publisher = awspublish.create({
params: {
Bucket: '...'
}
});
please update the README to say

var publisher = awspublish.create({
region: 'us-west-2',
params: {
Bucket: '...'
}
});
But thanks for the quick comment I have it working now.


Reply to this email directly or view it on GitHub.

@panmanphil
Copy link

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants