Slack Deployment Notifications

I’ve got a simple ASP.NET Core 2 web application setup hosted in AWS. My environment is built of 3 servers (build, web, and db). I want to minimize all AWS costs so I keep the servers off most of the time. Whenever turned on they get random public IP addresses from the AWS pool. I’ve got a really simple build and deployment process which apart from the usual elements also has the following step:

Send an email with either success or failure messages and the current public IP addresses of my servers

This is really important here as I would like to know where my stuff is without logging into AWS Console. Emails do work but Slack gives a more real-time experience without all the clunkiness emails come with. To get it done I have followed the below steps:

  • set up a new Slack channel #deployments
  • added the Incoming WebHooks integration and set it up to use the channel
  • stored my web hook URL in build config
  • my script is written in Powershell so I post to my web hook like this
function Send-SlackMessage()
{
    Param(
        [string]$Text,
        [string]$WebHookUri
    )

    $Payload =  @{
                    'channel'    = '#deployments';
                    'username'   = 'deployment-bot';
                    'text'       =  $Text;
                    'icon_emoji' = ':ghost:';
                } | ConvertTo-Json

    Invoke-WebRequest -Method POST -Uri $WebHookUri -Body @{'payload'=$Payload} > $null
}

And that’s it. Simple as that. No more emails.