mhart/aws4fetch

Trying to get it working with s3

devdilson opened this issue · 5 comments

Hi.

I have to authorize access to a file in S3(backed by Wasabi), however, the url generated does not work when accessing from a browser / postman and S3 always returns" SignatureDoesNotMatch" exception.

Interestinly, the code below returns my file when accessing with global.fetch using the signed request.

const signed = await client.sign('https://s3.wasabisys.com/coolbucket/coolfile.exe',
    {
      method: 'GET',
      aws: {
        service: 's3',
        region: 'us-east-1',
        signQuery: true
      },
    });
  console.log(signed.url)  => the url won't work in browser.
  return global.fetch(signed).then(e => {
    return e;
  })

`

I tested and had the same behavior on Amazon S3

Does anyone knows what this issue could be?

mhart commented

Can you clarify what you mean by:

I tested and had the behavior on Amazon S3

Can you clarify what you mean by:

I tested and had the behavior on Amazon S3

Wasabi implements the Amazon S3 API and the same aws4 signing.

I found the same behavior described on both Wasabi S3 and Amazon S3.

My use cases requires that I implement a cloudflare worker to generates the signed url for a file in a bucket.

I found a way to implement what I need using the aws-sdk.

If you need to generate a token to a s3 file, you can use this code:

import * as AWS from 'aws-sdk';

declare const AWS_ACCESS_KEY: any;
declare const AWS_SECRET_ACCESS_KEY: any;

const s3 = new AWS.S3({
  region: "us-east-1",
  credentials: new AWS.Credentials(AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY),
  endpoint: new AWS.Endpoint('s3.wasabisys.com')
});
addEventListener('fetch', (event) => {
  const url = s3.getSignedUrl('getObject', {
    Bucket: 'download.cooldomain.me',
    Key: 'coolfile.bin',
    Expires: 300
  });
  const response = {
    // The url replace is because we are on a custom main.
    url: url.replace('s3.wasabisys.com/', '')
  };
  event.respondWith(handleRequest(response))
})

export async function handleRequest(response: any): Promise<Response> {
  return new Response(JSON.stringify(response))
}


@devdilso u did not get this error when using aws-sdk?
aws/aws-sdk-js#2819