release/2026-04-03 - Clean up localstack endpoints / env check

This commit is contained in:
Dave
2026-04-01 14:39:34 -04:00
parent efdcd06921
commit 7688f22161
7 changed files with 73 additions and 44 deletions

View File

@@ -7,8 +7,7 @@ const {
CopyObjectCommand
} = require("@aws-sdk/client-s3");
const { defaultProvider } = require("@aws-sdk/credential-provider-node");
const { InstanceRegion } = require("./instanceMgr");
const { isString, isEmpty } = require("lodash");
const { InstanceRegion, InstanceIsLocalStackEnabled, InstanceLocalStackEndpoint } = require("./instanceMgr");
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
const createS3Client = () => {
@@ -17,10 +16,8 @@ const createS3Client = () => {
credentials: defaultProvider()
};
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
if (isLocal) {
S3Options.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
if (InstanceIsLocalStackEnabled()) {
S3Options.endpoint = InstanceLocalStackEndpoint();
S3Options.forcePathStyle = true; // Needed for LocalStack to avoid bucket name as hostname
}
@@ -105,7 +102,7 @@ const createS3Client = () => {
});
const presignedUrl = await getSignedUrl(s3Client, command, { expiresIn: 360 });
return presignedUrl;
}
};
return {
uploadFileToS3,
@@ -119,7 +116,4 @@ const createS3Client = () => {
};
};
module.exports = createS3Client();