awsprice

package module
v0.0.0-...-3926f62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2017 License: MIT Imports: 15 Imported by: 0

README

AWSPrice: AWS Pricing via a simple grammar

Installation

You should be able to

go get -u github.com/jbarratt/awsprice/...

and end up with an awsprice binary. (Which, as of now, has very limited functionality.)

Goals

Make it quick and easy to figure out prices for AWS configurations.

This is done via a simple grammar, like

$ awsprice '2 * m4.xlarge + db.t2.medium(engine=mariadb) + elb(transfer=500GB)'

(Warning, not yet implemented.)

The goal is to have a common engine power potentially a few different interfaces:

  • A command line tool $ awsprice c3.xlarge
  • A slackbot: @awsprice ebs(500G)
  • A single page webapp, with pretty/shareable HTML results

Implementation

The tools are built on the AWS Price List API.

Internally, it goes through a few phases:

  1. Fetching raw JSON offer data
  2. Processing that data into a format optimized for lookups
  3. Querying the data via the DSL/Grammar
  4. Presenting the results in various ways

Feature Set (Planned Delivery Order)

  • Initial CLI framework ✔
    • awsprice fetch ✔
    • awsprice process (optional -o 'db file') ✔
  • Simple lookup of EC2 information (only single region, no options) ✔
  • Additional EC2 dimensions (region) ✔
  • Basic RDS (region, multi-az, engine) ✔
  • Basic calculator support (+, -, parenthesis grouping)
  • EBS support
  • ELB support (including data transfer)
  • S3 support (GB)
  • RDS support (region, multi-az, engine, storage dimensions)
  • Cloudfront Support (transfer, price class)
  • EC2 Transit support
  • S3 transit support
  • 'vs' operator (comparing 2 stacks with each other)
  • EC2 OS

Internal Architecture

At the top level, the parser will identify an 'Offer' token, with a set of optional k=v arguments.

db.r3.xlarge(engine=mariadb)

There is a high level dispatch table: - given an identifier name - return the offer type

The dispatch table will then call the proper New{}Offer method, passing the arguments in. It will 'mix in' any of the global arguments, as well. For example

2 x m4.xlarge(os=Windows)  region=us-west-1

would

  • Look up m4.xlarge and discover it's an EC2 type

  • Construct a new EC2Offer, with {'os': 'Windows', 'region': 'us-west-1'} as arguments

    type OfferType int const ( EC2 OfferType = iota RDS )

    // when a new one is added link it in here map[string]OfferType

    // and construct a NewEC2OfferParam(k_v) EC2OfferParam { Name Region Os } map[EC2OfferParam]EC2Offer EC2Offer

The Offers all implement the Offer interface, which has some standard methods

Type() string
Description() string
Hourly() float64

This allows them to be displayed & totaled as needed.

StoreEC2(name string, params map[string]string, EC2Offer)
StoreRDS(name string, params map[string]string, RDSOffer)
Load(name string, params map[string]string) Offer
Search(name string, params map[string]string) []Offer

Documentation

Index

Constants

View Source
const HoursPerMonth = 730

HoursPerMonth is the average hours in a month. (365*24)/12 = 720

Variables

This section is empty.

Functions

func FetchJSON

func FetchJSON()

FetchJSON downloads all the AWS Pricing JSON files that the tool is aware of how to utilize.

func ParseInput

func ParseInput(pricer Pricer, input string) (string, error)

ParseInput takes a pricer and the input string and returns a string representation of the price

func PriceTable

func PriceTable(el OfferList) string

PriceTable returns a stringified table of all the results

func ProcessJSON

func ProcessJSON()

ProcessJSON does the top level dispatching of processing all the AWS pricing JSON files and distilling them.

Types

type EC2Attr

type EC2Attr struct {
	ServiceCode       string `json:"servicecode"`
	Location          string `json:"location"`
	LocationType      string `json:"locationType"`
	InstanceType      string `json:"instanceType"`
	CurrentGeneration string `json:"currentGeneration"`
	InstanceFamily    string `json:"instanceFamily"`
	VCPU              string `json:"vcpu"`
	Memory            string `json:"memory"`
	OperatingSystem   string `json:"operatingSystem"`
	Tenancy           string `json:"tenancy"`
}

EC2Attr identifies a selected list of useful attributes

type EC2Offer

type EC2Offer struct {
	Product EC2Attr
	Price   float64
}

EC2Offer The product/price details for a given EC2 Offering

func (EC2Offer) Columns

func (eo EC2Offer) Columns() []string

Columns returns a slice of the column names for this type

func (EC2Offer) HourlyPrice

func (eo EC2Offer) HourlyPrice() float64

HourlyPrice returns the fractional dollars per hour

func (EC2Offer) Name

func (eo EC2Offer) Name() string

Name returns the EC2 instance type

func (EC2Offer) RowData

func (eo EC2Offer) RowData() []string

RowData returns data for this item for tablular presentation Should be used in concert with Columns

func (EC2Offer) String

func (eo EC2Offer) String() string

String returns a simple string version of the pricing

func (EC2Offer) Type

func (eo EC2Offer) Type() OfferType

Type always returns EC2

type EC2OfferIndex

type EC2OfferIndex struct {
	FormatVersion   string                `json:"formatVersion"`
	Disclaimer      string                `json:"disclaimer"`
	PublicationDate string                `json:"publicationDate"`
	Products        map[string]EC2Product `json:"products"`
	Terms           EC2Terms              `json:"terms"`
}

EC2OfferIndex is at the root of the EC2 Offer JSON document

type EC2OfferParam

type EC2OfferParam struct {
	Region Region
	Name   string
}

EC2OfferParam stores the unique factors that determine an EC2 Offer

func NewEC2OfferParam

func NewEC2OfferParam(name string, attr map[string]string) (EC2OfferParam, error)

NewEC2OfferParam constructs an EC2 offer from a name & attributes

type EC2PriceDimensions

type EC2PriceDimensions struct {
	RateCode     string            `json:"rateCode"`
	Description  string            `json:"description"`
	Unit         string            `json:"unit"`
	PricePerUnit map[string]string `json:"pricePerUnit"`
}

EC2PriceDimensions stores various combinations of billing duration and currency

type EC2Product

type EC2Product struct {
	SKU           string  `json:"sku"`
	ProductFamily string  `json:"productFamily"`
	Attr          EC2Attr `json:"attributes"`
}

EC2Product identifies a single product 'leaf' in the JSON document

type EC2TermItem

type EC2TermItem struct {
	OfferTermCode   string                        `json:"offerTermCode"`
	SKU             string                        `json:"sku"`
	PriceDimensions map[string]EC2PriceDimensions `json:"priceDimensions"`
}

EC2TermItem is a given pricing term

type EC2Terms

type EC2Terms struct {
	OnDemand map[string]map[string]EC2TermItem
}

EC2Terms tracks the various terms. For now only OnDemand (not prepaid/spot/etc) is used.

type JSONOffer

type JSONOffer struct {
	OfferCode         string `json:"offerCode"`
	VersionIndexURL   string `json:"versionIndexUrl"`
	CurrentVersionURL string `json:"currentVersionUrl"`
}

JSONOffer identifies a singular Offer File for a given service

type Offer

type Offer interface {
	HourlyPrice() float64
	Type() OfferType
	Name() string
	String() string
	Columns() []string
	RowData() []string
}

Offer is the standard interface for offers. It is implemented by all objects which end up with prices

type OfferIndex

type OfferIndex struct {
	FormatVersion   string               `json:"formatVersion"`
	Disclaimer      string               `json:"disclaimer"`
	PublicationDate string               `json:"publicationDate"`
	Offers          map[string]JSONOffer `json:"offers"`
}

OfferIndex contains the top level information about the various Offers aka Amazon Service families

type OfferList

type OfferList []Offer

OfferList is a slice of Offers

func (OfferList) Len

func (slice OfferList) Len() int

func (OfferList) Less

func (slice OfferList) Less(i, j int) bool

func (OfferList) Swap

func (slice OfferList) Swap(i, j int)

type OfferType

type OfferType int

OfferType provides a set of constants that point to offer types

const (
	EC2 OfferType = iota
	RDS
	S3
	EBS
)

EC2 and other constants are the values of EC2 offers

type PriceDB

type PriceDB struct {
	// OfferLookup maps a name (like 'm4.xlarge') to a type (EC2)
	OfferLookup map[string]OfferType
	EC2         map[EC2OfferParam]EC2Offer
	RDS         map[RDSOfferParam]RDSOffer
}

PriceDB is the high level storage container for all the pricing data. It has utility methods for storing, loading, and searching the price data.

func LoadPriceDB

func LoadPriceDB() (*PriceDB, error)

LoadPriceDB loads the simple pricing "database" into memory The current implementation is a GOB file

func NewPriceDB

func NewPriceDB() *PriceDB

NewPriceDB creates a new PriceDB data structure

func (*PriceDB) Get

func (pd *PriceDB) Get(name string, attr map[string]string) (Offer, error)

Get returns an hourly price (or an error, if such a thing happens) when given a name and optional attributes

func (*PriceDB) Search

func (pd *PriceDB) Search(name string, attr map[string]string) []Offer

Search returns a slice of all matching Offers

func (*PriceDB) StoreEC2

func (pd *PriceDB) StoreEC2(name string, attr map[string]string, offer EC2Offer) error

StoreEC2 sets a value (with optional attributes) to a given hourly price

func (*PriceDB) StoreRDS

func (pd *PriceDB) StoreRDS(name string, attr map[string]string, offer RDSOffer) error

StoreRDS sets a value (with optional attributes) to a given hourly price

type Pricer

type Pricer interface {
	StoreEC2(name string, attr map[string]string, offer EC2Offer) error
	StoreRDS(name string, attr map[string]string, offer RDSOffer) error
	Get(name string, attr map[string]string) (Offer, error)
	Search(name string, attr map[string]string) []Offer
}

Pricer is a standard interface for price lookups. Given a name and defined attributes, (such as Region), it will return a floating point hourly price

type RDSAttr

type RDSAttr struct {
	ServiceCode       string `json:"servicecode"`
	Location          string `json:"location"`
	LocationType      string `json:"locationType"`
	InstanceType      string `json:"instanceType"`
	CurrentGeneration string `json:"currentGeneration"`
	InstanceFamily    string `json:"instanceFamily"`
	VCPU              string `json:"vcpu"`
	Memory            string `json:"memory"`
	OperatingSystem   string `json:"operatingSystem"`
	Tenancy           string `json:"tenancy"`
	DatabaseEngine    string `json:"databaseEngine"`
	DeploymentOption  string `json:"deploymentOption"`
}

RDSAttr identifies a selected list of useful attributes

type RDSOffer

type RDSOffer struct {
	Product RDSAttr
	Price   float64
}

RDSOffer The product/price details for a given RDS Offering

func (RDSOffer) Columns

func (ro RDSOffer) Columns() []string

Columns returns a slice of the column names for this type

func (RDSOffer) HourlyPrice

func (ro RDSOffer) HourlyPrice() float64

HourlyPrice returns the fractional dollars per hour

func (RDSOffer) Name

func (ro RDSOffer) Name() string

Name returns the RDS instance type

func (RDSOffer) RowData

func (ro RDSOffer) RowData() []string

RowData returns data for this item for tablular presentation Should be used in concert with Columns

func (RDSOffer) String

func (ro RDSOffer) String() string

String returns a simple string version of the pricing

func (RDSOffer) Type

func (ro RDSOffer) Type() OfferType

Type always returns RDS

type RDSOfferIndex

type RDSOfferIndex struct {
	FormatVersion   string                `json:"formatVersion"`
	Disclaimer      string                `json:"disclaimer"`
	PublicationDate string                `json:"publicationDate"`
	Products        map[string]RDSProduct `json:"products"`
	Terms           RDSTerms              `json:"terms"`
}

RDSOfferIndex is at the root of the RDS Offer JSON document

type RDSOfferParam

type RDSOfferParam struct {
	DatabaseEngine   string
	DeploymentOption string
	Region           Region
	Name             string
}

RDSOfferParam stores the unique factors that determine an RDS Offer

func NewRDSOfferParam

func NewRDSOfferParam(name string, attr map[string]string) (RDSOfferParam, error)

NewRDSOfferParam constructs an RDS offer from a name & attributes

type RDSPriceDimensions

type RDSPriceDimensions struct {
	RateCode     string            `json:"rateCode"`
	Description  string            `json:"description"`
	Unit         string            `json:"unit"`
	PricePerUnit map[string]string `json:"pricePerUnit"`
}

RDSPriceDimensions stores various combinations of billing duration and currency

type RDSProduct

type RDSProduct struct {
	SKU           string  `json:"sku"`
	ProductFamily string  `json:"productFamily"`
	Attr          RDSAttr `json:"attributes"`
}

RDSProduct identifies a single product 'leaf' in the JSON document

type RDSTermItem

type RDSTermItem struct {
	OfferTermCode   string                        `json:"offerTermCode"`
	SKU             string                        `json:"sku"`
	PriceDimensions map[string]RDSPriceDimensions `json:"priceDimensions"`
}

RDSTermItem is a given pricing term

type RDSTerms

type RDSTerms struct {
	OnDemand map[string]map[string]RDSTermItem
}

RDSTerms tracks the various terms. For now only OnDemand (not prepaid/spot/etc) is used.

type Region

type Region string

Region is a type identifying AWS Regions.

func NewRegion

func NewRegion(given string) (Region, error)

NewRegion returns a region type for any valid AWS region identifier

Directories

Path Synopsis
cmd
awsprice command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL