I am using AWS SDK V3 to upload/fetch files from R2. I am testing out the CreateBucketCommand and th

I am using AWS SDK V3 to upload/fetch files from R2. I am testing out the CreateBucketCommand and the ListBucketsCommand.
I am receiving these responses from both methods but no data:
response1= {
'$metadata': {
httpStatusCode: 200,
requestId: undefined,
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
}
}

I also added 'forcePathStyle: true' to the config which fixed the previous error of 'NoSuchBucket' when trying to create a bucket,
not sure how or why I had to do that. I've also tested this with AWS S3 and it creates the buckets and lists the buckets with no problems.

The code:
const options = {
  region: 'us-east-1',
  accessKeyId: process.env.ACCESS_KEY_ID!,
  secretAccessKey: process.env.SECRET_ACCESS_KEY!,
  endpoint: process.env.S3_ENDPOINT!,
  bucketName: 'test-bucket-1234-abcd-5678-efgh',
  maxFileSize: 10,
  validMimeType: [],
  format: 'url',
  urlExpiration: 10,
  path: path.join(__dirname, 'downloads')
};

describe('s3Controller', () => {
  it('should create a bucket', async () => {
    const input = {
      Bucket: options.bucketName,
    };

    try {
      const command = new CreateBucketCommand(input);
      const response = await client.send(command);
      console.log('response1=', response);

    } catch(err) {
      console.log('err=', err);
    }
    expect(response).toEqual({});
  });
});

describe('s3Controller', () => {
  it('should list buckets', async () => {

    try {
      const command = new ListBucketsCommand('');
      const response = await client.send(command);
      console.log('response2=', response);

    } catch(err) { 
      console.log('err=', err);
    }
    expect(response).toEqual({});
  });
});

Any help would be much appreciated.
Was this page helpful?