|
1 | 1 | import { getModelOptions } from '@/ai/gateway'; |
2 | | -import { s3Client } from '@/app/s3'; |
3 | 2 | import { decrypt, type EncryptedData } from '@/lib/encryption'; |
4 | | -import { GetObjectCommand } from '@aws-sdk/client-s3'; |
| 3 | +import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3'; |
5 | 4 | import { db } from '@db'; |
6 | 5 | import { logger, queue, task } from '@trigger.dev/sdk'; |
7 | 6 | import { generateObject } from 'ai'; |
@@ -38,13 +37,29 @@ export const executeAutomationScript = task({ |
38 | 37 | const { orgId, taskId } = payload; |
39 | 38 | const logs: string[] = []; |
40 | 39 |
|
| 40 | + if ( |
| 41 | + !process.env.APP_AWS_REGION || |
| 42 | + !process.env.APP_AWS_ACCESS_KEY_ID || |
| 43 | + !process.env.APP_AWS_SECRET_ACCESS_KEY |
| 44 | + ) { |
| 45 | + throw new Error('AWS S3 credentials or configuration missing. Check environment variables.'); |
| 46 | + } |
| 47 | + |
41 | 48 | try { |
42 | 49 | logger.info(`Executing automation script for task ${taskId} in org ${orgId}`); |
43 | 50 |
|
44 | 51 | // Fetch the script from S3 |
45 | 52 | const scriptKey = `${orgId}/${taskId}.automation.js`; |
46 | 53 | logs.push(`[SYSTEM] Fetching script from S3: ${scriptKey}`); |
47 | 54 |
|
| 55 | + const s3Client = new S3Client({ |
| 56 | + region: process.env.APP_AWS_REGION, |
| 57 | + credentials: { |
| 58 | + accessKeyId: process.env.APP_AWS_ACCESS_KEY_ID, |
| 59 | + secretAccessKey: process.env.APP_AWS_SECRET_ACCESS_KEY, |
| 60 | + }, |
| 61 | + }); |
| 62 | + |
48 | 63 | const { Body } = await s3Client.send( |
49 | 64 | new GetObjectCommand({ |
50 | 65 | Bucket: process.env.TASKS_AUTOMATION_BUCKET, |
|
0 commit comments