diff --git a/backend/src/tasks/scanExecution.ts b/backend/src/tasks/scanExecution.ts index ded5194b9..c3d959984 100644 --- a/backend/src/tasks/scanExecution.ts +++ b/backend/src/tasks/scanExecution.ts @@ -1,14 +1,17 @@ -import { SQSEvent, SQSRecord } from 'aws-lambda'; +import { Handler, SQSRecord } from 'aws-lambda'; import * as AWS from 'aws-sdk'; const ecs = new AWS.ECS(); const sqs = new AWS.SQS(); -export const invokeFargateTask = async (event: SQSEvent): Promise => { +export const handler: Handler = async (event) => { try { + // Get the SQS record and message body const sqsRecord: SQSRecord = event.Records[0]; const commandOptions: string = sqsRecord.body; + console.log(commandOptions); + // Get the ARN of the SQS queue from the event const sqsQueueArn: string | undefined = sqsRecord.eventSourceARN; @@ -24,11 +27,12 @@ export const invokeFargateTask = async (event: SQSEvent): Promise => { .getQueueAttributes(sqsQueue) .promise(); const sqsQueueUrl = queueAttributesResponse.Attributes?.QueueUrl; - + console.log(sqsQueueUrl); if (!sqsQueueUrl) { throw new Error('SQS Queue URL not found'); } + // Run command in queue message in Fargate const params: AWS.ECS.RunTaskRequest = { cluster: process.env.FARGATE_CLUSTER_NAME!, taskDefinition: process.env.FARGATE_TASK_DEFINITION_NAME!, @@ -50,7 +54,6 @@ export const invokeFargateTask = async (event: SQSEvent): Promise => { ] } }; - const data = await ecs.runTask(params).promise(); console.log('Fargate task started:', data);