`S3Client.listObjects` always return an empty array
oleiade opened this issue · comments
What
It's been reported that the S3Client.listObjects
returns an empty Array. We were able to reproduce the issue and should work towards a better understanding of what happens and a fix.
const s3 = new S3Client(awsConfig)
const objects = s3.listObjects(existingBucketNameWithExistingObjects)
console.log(objects) // []
Considerations
Ideally, we should consider introducing end2end tests to assert we don't break these kinds of operations in the future. localstack has been mentioned many times and seems a good option. As the signature process has unit tests asserting its correctness, we probably can afford a solution that doesn't require any authentication.
How
Needs investigation
Definition of done
For a given bucket, containing N files, a user with the appropriate permissions should be able to retrieve an array of N objects by calling S3Client.listObjects
on it.
Maybe as a result of my session token #5 not having enough rights?
Found what was causing the issue (my typescript noobness for the most part): list-type=2&prefix=${prefix}
. As it turns out, prefix
is an optional string parameter, I assumed that if not set it would hold an empty string (as optional types are a bit... atypical in TS). It would rather hold undefined
.
Which would lead to the URL ending up looking like: https://test-jslib-aws.s3.us-east-1.amazonaws.com/?list-type=2&prefix=undefined
, effectively asking AWS to send us back the list of objects prefixed with undefined
. Not what we intended...