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.
Prerequisites#
Deploying the example#
-
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 stack, which is an isolated deployment target for this example:
Terminal window pulumi stack init -
Install dependencies:
Terminal window go mod download -
Set the required configuration variables for this program:
Terminal window pulumi config set slackWebhookURL 'YOUR_SLACK_WEBHOOK_URL' --secretOptionally, 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!' -
Deploy the stack:
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.
Cleaning up#
Once you’re finished experimenting, tear down your stack’s resources by destroying and removing it:
pulumi destroypulumi stack rm