Skip to content

Commit

Permalink
convert "ecs stopped task" event to Slack message
Browse files Browse the repository at this point in the history
  • Loading branch information
svonworl authored Jan 18, 2024
1 parent 6eb8130 commit a675de7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion cloud-watch-to-slack-testing/deployment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit a675de7

Please sign in to comment.