Giter Site home page Giter Site logo

aws-cost-billing-alarm's Introduction

Creating AWS Cost Explorer billing cloud watch with Terraform

What is this?

Like the title says, this Terraform code can be used to create Cost Explorer billing CloudWatch alarm, an SNS resource, and an email subscription to the created SNS resource.

Prerequisites

  1. Configure AWS CLI. Once set up, you can list all configuration data, and the profile name using the following commands:
❯ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************OEWE shared-credentials-file
secret_key     ****************Edl1 shared-credentials-file
    region           ap-southeast-2      config-file    ~/.aws/config

❯ aws configure list-profiles
default
  1. Install terraform on your machine by following the Install Terraform instruction. If you use Homebrew to install packages on a macOS machine, you can install terraform by running the commands:
❯ brew tab hashicorp/tap
❯ brew install hashicorp/tap/terraform 

Usage

  1. Clone this repository to your local machine, change into the cloned directory:
❯ git clone https://github.com/kenno/aws-cost-billing-alarm

❯ cd aws-cost-billing-alarm

  1. Create a file named terraform.tfvars with the following contents:
aws_profile = "default"                  # AWS CLI profile name

aws_account_id = "123456789012"          # Replace with your AWS account ID
endpoint_email = "[email protected]" # Email to receive notificantion
  1. Configure the currency (default USD) and monthly_billing_thresshold (default $20) as desired in the main.tf file. The example below sets monthly_billing_thresshold to $300 USD.
module "billing_cloudwatch_alert" {
  ...
  monthly_billing_threshold = 300
  currency = "USD"
}
  1. You are now ready to run terraform to create a Cloudwatch billing alarm.
❯ terraform init
❯ terraform plan
❯ terraform apply

Note: when asked "Do you want to perform these actions?", enter 'yes' if you want to proceed.

  1. If everything works well, you should receive an email to confirm whether your subscription to a SNS notification.

  2. (Optional) To destroy all resources created by this Terraform, you can simply run:

❯ terraform destroy

Credits

The code depends on the cost-billing-alarm module.

aws-cost-billing-alarm's People

Contributors

kenno avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.