I have an issue with the S3 Client from aws sdk v3 :
If i use the S3Client, as specified in the documentation, with the credentials provided using the environent variables, i get the error The AWS Access Key Id you provided does not exist in our records.
At first i thought it was because i didn't use the correct AWS_ACCESS_KEY_ID
, but adding this line just after the client initialization fixed the issue, and logged the correct values :
s3.config.credentials().then(console.log)
What bother me the most is the fact that if i call this line anywhere else (ie: in a async function), it does not fix the issue.
- Why does this async function call fix the rest of the execution ?
- Does it only fix the client temporarly ? (the client stay instantiated for multiple function calls)
- Can the promise end to late : after the fist call of the client ?
- Why doesn't it work when called right before an s3 call (with or without
await
) ?
Here is my code :
const s3Config: S3ClientConfig = {}
s3Config.endpoint = new HttpRequest({...} as Endpoint) // used with a local s3 server
const s3 = new S3Client(s3Config);
// this is the hack
s3.config.credentials().then(console.log)
export const upload = async (...) => {
// here it does not work
// await s3.config.credentials().then(console.log)
const streamUpload = new Upload({client: s3,...})
return await streamUpload.done()
}
export const getTempLink = async (...) => {
// here it does not work
// await s3.config.credentials().then(console.log)
//* Get the pre-signed url
const command = new GetObjectCommand({Bucket,Key})
return await getSignedUrl(s3 as any, command as any, { expiresIn })
}
Thanks for your help !