Issue uploading an image to an s3 bucket

I am trying to upload an image to an s3 bucket but have been having some issues.
Following the examples in the documentation, I have this code:

import { check } from 'k6';
import exec from 'k6/execution';
import http from 'k6/http';
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.7.1/s3.js';

const awsConfig = new AWSConfig({
  region: 'eu-east-1',
  accessKeyId: 'sshhh',
  secretAccessKey: 'shhhh',
});

const s3 = new S3Client(awsConfig);
const testBucketName = 'the-bucket';
const fileName = 'some_image.JPG';
const testInputFileKey = 'file_a/' + fileName;
const testOutputFileKey = open('local_dir/' + fileName, 'r');

export default function () {
  s3.putObject(testBucketName, testInputFileKey, testOutputFileKey);
}

when I run this, I get:

S3ServiceError: The request signature we calculated does not match the signature you provided. Check your key and signing method.

  • I know the bucket name is correct since I used “listBuckets()” to search for the bucket
  • the folder (key) is also correct because I used “listObjects()” to view all images under that prefix key

I am really at my wits end and would really appreciate any help.
Thank you very much in advance.

Hmm since you are trying to upload a binary file, but you are opening it as a string, something might get mangled with the encoding :thinking: Try to pass the b flag to open(), like this:

const testOutputFileKey = open('local_dir/' + fileName, 'b');

That way it will return an ArrayBuffer