Skip to content

Commit 8bfae95

Browse files
authored
Merge pull request #1191 from trycompai/main
[comp] Production Deploy
2 parents 082151a + fa2933a commit 8bfae95

3 files changed

Lines changed: 39 additions & 14 deletions

File tree

apps/app/src/actions/files/upload-file.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import { BUCKET_NAME, s3Client } from '@/app/s3';
44
import { logger } from '@/utils/logger';
5+
6+
// This log will run as soon as the module is loaded.
7+
logger.info('[uploadFile] Module loaded.');
8+
59
import { GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
610
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
711
import { AttachmentEntityType, AttachmentType, db } from '@db';

apps/app/src/app/s3.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,24 @@ if (!APP_AWS_ACCESS_KEY_ID || !APP_AWS_SECRET_ACCESS_KEY || !BUCKET_NAME || !APP
2020

2121
// Create a single S3 client instance
2222
// Add null checks or assertions if the checks above don't guarantee non-null values
23-
export const s3Client = new S3Client({
24-
region: APP_AWS_REGION!,
25-
credentials: {
26-
accessKeyId: APP_AWS_ACCESS_KEY_ID!,
27-
secretAccessKey: APP_AWS_SECRET_ACCESS_KEY!,
28-
},
29-
});
23+
24+
export const s3Client = new S3Client(
25+
// If we are on Vercel, we MUST provide explicit credentials.
26+
process.env.VERCEL === '1'
27+
? {
28+
region: APP_AWS_REGION!,
29+
credentials: {
30+
accessKeyId: APP_AWS_ACCESS_KEY_ID!,
31+
secretAccessKey: APP_AWS_SECRET_ACCESS_KEY!,
32+
},
33+
}
34+
: // For any other environment (like AWS ECS or local dev),
35+
// we only need to provide the region. The AWS SDK will
36+
// automatically find the credentials from the environment.
37+
{
38+
region: APP_AWS_REGION!,
39+
},
40+
);
3041

3142
// Ensure BUCKET_NAME is exported and non-null checked if needed elsewhere explicitly
3243
if (!BUCKET_NAME && process.env.NODE_ENV === 'production') {

apps/portal/src/utils/s3.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,23 @@ if (!APP_AWS_ACCESS_KEY_ID || !APP_AWS_SECRET_ACCESS_KEY || !BUCKET_NAME || !APP
2121

2222
// Create a single S3 client instance
2323
// Add null checks or assertions if the checks above don't guarantee non-null values
24-
export const s3Client = new S3Client({
25-
region: APP_AWS_REGION!,
26-
credentials: {
27-
accessKeyId: APP_AWS_ACCESS_KEY_ID!,
28-
secretAccessKey: APP_AWS_SECRET_ACCESS_KEY!,
29-
},
30-
});
24+
export const s3Client = new S3Client(
25+
// If we are on Vercel, we MUST provide explicit credentials.
26+
process.env.VERCEL === '1'
27+
? {
28+
region: APP_AWS_REGION!,
29+
credentials: {
30+
accessKeyId: APP_AWS_ACCESS_KEY_ID!,
31+
secretAccessKey: APP_AWS_SECRET_ACCESS_KEY!,
32+
},
33+
}
34+
: // For any other environment (like AWS ECS or local dev),
35+
// we only need to provide the region. The AWS SDK will
36+
// automatically find the credentials from the environment.
37+
{
38+
region: APP_AWS_REGION!,
39+
},
40+
);
3141

3242
// Ensure BUCKET_NAME is exported and non-null checked if needed elsewhere explicitly
3343
if (!BUCKET_NAME && process.env.NODE_ENV === 'production') {

0 commit comments

Comments
 (0)