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:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-go-console-slack-notificationcd pulumi-examples/aws-go-console-slack-notificationThis 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.
Deploying the App#
To deploy your infrastructure, follow the below steps.
Prerequisites#
Steps#
After cloning this repo, run these commands from the working directory:
-
Build the handler:
-
For developers on Linux and macOS:
Terminal window make -
For developers on Windows:
-
Get the
build-lambda-ziptool:Terminal window set GO111MODULE=ongo.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip -
Use the tool from your GOPATH:
Terminal window set GOOS=linuxset GOARCH=amd64set CGO_ENABLED=0go build -o handler\dist\handler handler\handler.go%USERPROFILE%\Go\bin\build-lambda-zip.exe -o handler\dist\handler.zip handler\dist\handler
-
-
-
Create a new Pulumi stack, which is an isolated deployment target for this example:
Terminal window pulumi stack init -
Set the required configuration variables for this program:
Terminal window pulumi config set slackWebhookURL 'YOUR_SLACK_WEBHOOK_URL' -
Execute the Pulumi program to create our lambda:
Terminal window pulumi up -
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 upwill update your lambda. Customize the Slack message username or text with the following configuration values:Terminal window pulumi config set slackMessageUsername 'Console Change Monitor'pulumi config set slackMessageText ':warning: Somebody made a change in the console!' -
Afterwards, destroy your stack and remove it:
Terminal window pulumi destroy --yespulumi stack rm --yes