Skip to main content

AWS Console change Slack notifier in Go

Deploy necessary resources to notify Slack when an operation is performed via the AWS Console.

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-go-console-slack-notification
cd pulumi-examples/aws-go-console-slack-notification

This example deploys a Lambda function and relevant CloudTrail and CloudWatch resources to send a Slack notification for any resource operation that is performed via the AWS Console.

Note: This application sets up the necessary infrastructure across each AWS region in your account that is opt-in-not-required or opted-in. The Pulumi application uses the DescribeRegions API via aws-sdk-go to query for available regions.

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Go

Deploying the example#

  1. Build the handler:

    • For developers on Linux and macOS:

      Terminal window
      make
    • For developers on Windows:

      • Get the build-lambda-zip tool:

        Terminal window
        set GO111MODULE=on
        go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
      • Use the tool from your GOPATH:

        Terminal window
        set GOOS=linux
        set GOARCH=amd64
        set CGO_ENABLED=0
        go build -o handler\dist\handler handler\handler.go
        %USERPROFILE%\Go\bin\build-lambda-zip.exe -o handler\dist\handler.zip handler\dist\handler
  2. Create a new stack, which is an isolated deployment target for this example:

    Terminal window
    pulumi stack init
  3. Install dependencies:

    Terminal window
    go mod download
  4. Set the required configuration variables for this program:

    Terminal window
    pulumi config set slackWebhookURL 'YOUR_SLACK_WEBHOOK_URL' --secret

    Optionally, customize the Slack message username or text:

    Terminal window
    pulumi config set slackMessageUsername 'Console Change Monitor'
    pulumi config set slackMessageText ':warning: Somebody made a change in the console!'
  5. Deploy the stack:

    Terminal window
    pulumi up
  6. Perform a change in the AWS Console and look for a notification in your Slack channel. Note: you must perform a write such as adding or removing tags from a resource, launching an instance, or deleting a resource.

    From there, feel free to experiment. Simply making edits, rebuilding your handler, and running pulumi up will update your Lambda.

Cleaning up#

Once you’re finished experimenting, tear down your stack’s resources by destroying and removing it:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.