I am trying to generate a presignedUrl for objects in a Wasabi bucket (not the actual Amazon S3) using the S3 API. I have it generating the URL, but for some reason, it's not adding the region/endpoint to the URL.
So, instead of https://s3.us-central-1.wasabisys.com/bucket/filepath
I get https://bucket/filepath
Here is my code:
exports.getPresignedUrl = functions.https.onCall(async (data, ctx) => {
const wasabiObjKey = `${data.bucket_prefix ? `${data.bucket_prefix}/` : ''}${data.uid.replace(/-/g, '_').toLowerCase()}/${data.uid.replace(/-/g, '_').toLowerCase()}${data.variation ? `_${data.variation.replace(/\./g, '').toLowerCase()}` : ''}.zip`
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3')
const s3 = new S3Client({
bucketEndpoint: ee_products_bucket_endpoint,
region: functions.config().s3_bucket.region,
credentials: {
secretAccessKey: functions.config().s3.secret,
accessKeyId: functions.config().s3.access_key
}
})
const command = new GetObjectCommand({
Bucket: functions.config().s3_bucket.name,
Key: wasabiObjKey,
})
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner")
try {
const url = getSignedUrl(s3, command, { expiresIn: 60 })
return url
}
catch(err) {
return `Error: ${err}`
}
})
I finally figured out the solution, and it was that
functions.config().s3_bucket.endpoint
was present online - but I didn't deploy it to the .runtimeconfig.json in my emulators, so the string was null.The command to env vars locally to test:
Windows:
OSX: