-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for stack set notifications
- Loading branch information
Showing
4 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"version": "0", | ||
"id": "f8698be4-5139-e30e-e8c1-1462bbbe764e", | ||
"detail-type": "CloudFormation StackSet Operation Status Change", | ||
"source": "aws.cloudformation", | ||
"account": "048723829744", | ||
"time": "2024-04-22T03:27:25Z", | ||
"region": "us-east-2", | ||
"resources": [ | ||
"arn:aws:cloudformation:us-east-2:048723829744:stackset/org-sink-event-rules-management-account:76f20da2-a8b8-46bc-8556-2257dab866d0" | ||
], | ||
"detail": { | ||
"stack-set-arn": "arn:aws:cloudformation:us-east-2:048723829744:stackset/org-sink-event-rules-management-account:76f20da2-a8b8-46bc-8556-2257dab866d0", | ||
"stack-set-operation-id": "e22fb8de-5ac4-c606-e4a9-2ed951a823c5", | ||
"action": "CREATE", | ||
"status-details": { "status": "SUCCEEDED" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
59 changes: 59 additions & 0 deletions
59
src/status-change-slack-notifications/stack-set-change.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import regions from "./regions.mjs"; | ||
import accounts from "./accounts.mjs"; | ||
|
||
const SLACK_DEBUG_CHANNEL = "G2QHC11SM"; // #ops-debug | ||
const SLACK_ICON = ":ops-cloudformation:"; | ||
const SLACK_USERNAME = "AWS CloudFormation"; | ||
|
||
function colorForResourceStatus(status) { | ||
console.log(status); | ||
return "#000000"; | ||
} | ||
|
||
export default function message(event) { | ||
const stackSetArn = event.detail["stack-set-arn"]; | ||
|
||
const stackSetID = stackSetArn.split("stackset/")[1]; | ||
const stackSetName = stackSetID.split(":")[0]; | ||
|
||
const { status } = event.detail["status-details"]; | ||
|
||
const { region } = event; | ||
const stackUrl = `https://${region}.console.aws.amazon.com/cloudformation/home?region=${region}#/stacksets/${stackSetID}/info`; | ||
|
||
const deepLinkRoleName = "ViewOnlyAccess"; | ||
const urlEncodedStackUrl = encodeURIComponent(stackUrl); | ||
const deepStackUrl = `https://d-906713e952.awsapps.com/start/#/console?account_id=${event.account}&role_name=${deepLinkRoleName}&destination=${urlEncodedStackUrl}`; | ||
|
||
const regionNickname = regions(region); | ||
const accountNickname = accounts(event.account); | ||
const header = [ | ||
`*<${deepStackUrl}|${accountNickname} - ${regionNickname} » ${stackSetName}>*`, | ||
`Stack Set Status Change: *${status}*`, | ||
].join("\n"); | ||
|
||
const fallback = `${accountNickname} - ${regionNickname} » Stack Set ${stackSetName} is now ${status}`; | ||
|
||
const msg = { | ||
username: SLACK_USERNAME, | ||
icon_emoji: SLACK_ICON, | ||
channel: SLACK_DEBUG_CHANNEL, | ||
attachments: [ | ||
{ | ||
color: colorForResourceStatus(status), | ||
fallback, | ||
blocks: [ | ||
{ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text: header, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
return msg; | ||
} |