I encountered an issue with the S3 Client from aws sdk v3:
When using the S3Client as outlined in the documentation and providing credentials via environment variables, I received an error message stating
The AWS Access Key Id you provided does not exist in our records.
Initially, I believed the problem was due to incorrect usage of AWS_ACCESS_KEY_ID
. However, adding a specific line of code right after initializing the client resolved the error and correctly logged the values:
s3.config.credentials().then(console.log)
What puzzles me is that if I call this line within an asynchronous function or at any other point in the code, it no longer resolves the issue.
- Why does calling this async function resolve subsequent executions?
- Does it only temporarily fix the client, which remains instantiated for multiple function calls?
- Could the promise be getting resolved too late – after the initial client call?
- Why doesn't it work when called just before an s3 call (with or without
await
)?
Here's the relevant portion of my code:
const s3Config: S3ClientConfig = {}
s3Config.endpoint = new HttpRequest({...} as Endpoint) // used with a local s3 server
const s3 = new S3Client(s3Config);
// Workaround solution
s3.config.credentials().then(console.log)
export const upload = async (...) => {
// Issue observed here
// await s3.config.credentials().then(console.log)
const streamUpload = new Upload({client: s3,...})
return await streamUpload.done()
}
export const getTempLink = async (...) => {
// Issue observed here
// 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 })
}
Thank you for your assistance!