gatsby-uc/gatsby-plugin-s3

SignatureDoesNotMatch when creating redirects with special characters

marcus13371337 opened this issue · 5 comments

Hello!

I'm using your plugin to deploy our website to an S3 bucket. When I've implemented some redirects I get the following error:

SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
s3.js:700 Request.extractError

One example of the redirects I'm trying to create:

createRedirect({
   fromPath: `/p/123456/`,
   toPath: '/argument-f%C3%B6r-testning/p/123456/', //special character ö is encoded inside
   isPermanent: true
})

Which in code looks like this:

 await createPage({
    path: node.fields.slug,
    component: resolve(
       __dirname,
      `../../src/templates/myPage.tsx`
     ),
     context: {
       id: node.id,
     },
 });

 await createRedirect({
      fromPath: `/p/${node.productNumber}/`,
      toPath: node.fields.slug,
      isPermanent: true,
  });

Note that I'm using the same slug as I'm doing when creating the page. What am I doing wrong?

Just as a sanity check, does it work when your path does not contain special characters? SignatureDoesNotMatch can indicate incorrect credentials.

Also, what's your config look like? Are you using generateRedirectObjectsForPermanentRedirects?

Hi,

Yes, it normally works for other files (the error is thrown after some files have been uploaded).

Actually, now when I'm looking at it, we do not escape the characters in the node.fields.slug-field, so the value of that is actually: '/argument-för-testning/p/123456/', which is the path that is printed in s3.redirectsObject.json. Should that be escaped?

Added encoding and it seems to work much better. However, that seems to me as an inconsistency compared to how gatsby's createPage works. Also, a better error message would be really helpful as I've been struggling with this for a while.

Love the plugin, super simple and works like a charm for our page! Keep up the good work

The AWS docs don't mention any requirement to escape the value, but I guess it makes sense that it has to be URL safe. We should implement escaping. Still, I'm surprised that you get a SignatureDoesNotMatch error, that seems very strange.

Unfortunately aws-sdk doesn't often provide useful error messages, and if we tried to read them and provide more helpful ones it would really just be guesswork.