coreos/grafiti

Name: grafiti

Owner: CoreOS

Description: Tag and remove AWS Resources with Automation

Created: 2017-04-04 13:49:09.0

Updated: 2018-04-25 06:47:12.0

Pushed: 2017-09-12 12:38:02.0

Homepage:

Size: 15274

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Grafiti

Build Status

Grafiti is a tool for parsing, tagging, and deleting AWS resources.

Each sub-command can be used in a sequential pipe, or individually.

Motivating Example

We listen to CloudTrail events, and tag created resources with a default expiration of 2 weeks and the ARN of the creating user.

Every day, we can query the resource tagging API for resources that will expire in one week, and the owners can be notified via email/Slack.

Every day, we also query for resources that have expired, and delete them.

Installation

Ensure you have the following installed:

Retrieve and install grafiti (the binary will be in $GOPATH/bin):

et -u github.com/coreos/grafiti/cmd/grafiti

If $GOPATH/src/github.com/coreos/grafiti is already present, simply install grafiti:

nstall github.com/coreos/grafiti/cmd/grafiti

or use the Makefile (requires make):

 install
jq installation

jq is a CLI JSON parsing tool that grafiti uses internally to evaluate config file expressions, and must be installed before running grafiti. This program is quite useful for parsing grafiti input/output as well. You can find download instructions on the jq website.

Usage

Grafiti commands
e:
afiti [flags]
afiti [command]

lable Commands:
lete      Delete resources in AWS by tag.
lter      Filter AWS resources by tag.
lp        Help about any command
rse       Parse resource data from CloudTrail logs.
g         Tag resources in AWS.

s:
, --config string   Config file (default: $HOME/.grafiti.toml).
  --debug           Enable debug logging.
  --dry-run         Output changes to stdout instead of AWS.
, --help            help for grafiti
, --ignore-errors   Continue processing even when there are API errors.

"grafiti [command] --help" for more information about a command.
Configure AWS

You will need to configure your machine to talk to AWS prior to running grafiti; configuring both credentials and AWS region is required.

Credentials

There are several ways to configure your AWS credentials for the Go SDK. Grafiti supports all methods because it uses the Go SDK and does not implement its own credential handling logic.

Configure Grafiti

Grafiti takes a config file which configures it's basic function.

urceTypes = ["AWS::EC2::Instance"]
our = 0
tHour = -8
imeStamp = "2017-06-14T01:01:01Z"
tTimeStamp = "2017-06-13T01:01:01Z"
umRequestRetries = 11
udeEvent = false
atterns = [
CreatedBy: .userIdentity.arn}"

erPatterns = [
TaggingMetadata.ResourceType == \"AWS::EC2::Instance\""

ir = "/var/log"
Environment variables

Grafiti can be configured with the following environment variables in addition to, or in lieu of, a config file:

If one of the above variables is set, its' data will be used as the corresponding config value and override that config file field if set. Setting environment variables allows you to avoid using a config file in certain cases; some config file fields are complex, ex. tagPatterns and filterPatterns, and cannot be succinctly encoded by environment variables. See this pull request for the reasoning behind this hierarchy.

Further documentation

A note on resource deletion order.

Examples of grafiti in action:

Kubernetes:

Usage notes and tips:


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.