Skip to content

Terraform boilerplate for slack notifications on EC2 instance alarms

Notifications You must be signed in to change notification settings

mvandiepen/aws-alarm-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Alarm notifier boilerplate

Terraform

Installation

# Terraform CLI
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
terraform init

# AWS CLI
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
rm AWSCLIV2.pkg

Setup

Add access key from your AWS account to ~/.aws/credentials:

[demo-profile]
aws_access_key_id=...
aws_secret_access_key=...

Update aws_key_pair resource to contain your public key:

resource "aws_key_pair" "demo_key" {
  key_name   = "demokey"
  public_key = "ssh-rsa your-public-key-here [email protected]"
}

Slack

Setup webhook

  • Create a new app for your slack workspace
  • Turn on the Incoming Webhooks feature
  • Add new webhook to workspace

Update aws_lambda_function with your webhook url and the channel you want to notify:

resource "aws_lambda_function" "alarm_notifier_lambda" {
  # ... omitted
  
  environment {
    variables = {
      slack_channel     = "#channel-name"
      slack_webhook_url = "your-webhook-url"
    }
  }
}

Lambda

Changing the function

You can change the lambda function in the deployment-package directory. To upload the new function you can run yarn zip within the deployment-package directory and run terraform apply afterwards.

Ready to run

Just run terraform plan to see what will get setup/changed and terraform apply to actually apply it.

About

Terraform boilerplate for slack notifications on EC2 instance alarms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published