From a675de727eafb5a72a81561d18a4b5abedaf5a91 Mon Sep 17 00:00:00 2001 From: Steve Von Worley Date: Thu, 18 Jan 2024 14:11:34 -0800 Subject: [PATCH] convert "ecs stopped task" event to Slack message https://ucsc-cgl.atlassian.net/browse/SEAB-5860 --- .../deployment/index.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cloud-watch-to-slack-testing/deployment/index.js b/cloud-watch-to-slack-testing/deployment/index.js index fbc84a6..3b2c448 100644 --- a/cloud-watch-to-slack-testing/deployment/index.js +++ b/cloud-watch-to-slack-testing/deployment/index.js @@ -246,6 +246,27 @@ function s3ActivityMessageText(message) { return `${userName} generated S3 event ${eventName} from region ${awsRegion} for bucket ${bucketName} in Dockstore ${dockstoreEnvironment}`; } +function ecsActivityMessageText(message) { + if (message["detail-type"] === "ECS Task State Change") { + return ecsTaskStateChangeMessageText(message); + } else { + return ecsAutoScalingMessageText(message); + } +} + +function ecsTaskStateChangeMessageText(message) { + const taskArn = message?.detail?.taskArn; + const lastStatus = message?.detail?.lastStatus; + let messageText = `Task ${taskArn} is now ${lastStatus}`; + ["startedAt", "stoppedAt", "stoppedReason"].forEach((name) => { + const value = message?.detail?.[name]; + if (value != undefined) { + messageText += `\n${name}: ${value}`; + } + }); + return messageText; +} + function ecsAutoScalingMessageText(message) { const serviceName = message.detail.requestParameters.service; const newDesiredCount = message.detail.requestParameters.desiredCount; @@ -268,7 +289,7 @@ function messageTextFromMessageObject(message) { } else if (message.source === "dockstore.deployer") { return dockstoreDeployerMessageText(message); } else if (message.source === "aws.ecs") { - return ecsAutoScalingMessageText(message); + return ecsActivityMessageText(message); } else if (message.source === "aws.cloudwatch") { return cloudWatchEventBridgeAlarmMessageText(message); } else {