awsPricingTyper

package module
v0.0.0-...-7da9aa7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

README

aws pricing typer

Build Status Coverage Status Go Report Card

about

Using the Go SDK to query the AWS Pricing API for Products (metadata plus pricing detail) returns a slice of type: aws.JSONValue that's defined as: map[string]interface{}. This library takes the output and returns the documents in structs with their concrete types.

note

  • AWS API credentials are required in order to query the pricing API
  • "The Price List Service API provides pricing details for your information only. If there is a discrepancy between the offer file and a service pricing page, AWS charges the prices that are listed on the service pricing page. For more information about AWS service pricing, see Cloud Services Pricing."

usage

package main

import (
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/pricing"
	"github.com/jonhadfield/aws-pricing-typer"
)

func main() {
	pricingAPIRegion := "us-east-1"

	// get pricing client
	sess, _ := session.NewSession(&aws.Config{Region: &pricingAPIRegion})
	svc := pricing.New(sess)

	// create request criteria
	ec2ServiceCode := "AmazonEC2"
	formatVer := "aws_v1"
	typeTerm := pricing.FilterTypeTermMatch

	// create filters
	locationKey := "location"
	locationValue := "EU (Ireland)"
	instanceTypeKey := "instanceType"
	instanceTypeValue := "m4.large"
	var priceFilters []*pricing.Filter
	priceFilters = append(priceFilters, &pricing.Filter{
		Type:  &typeTerm,
		Field: &locationKey,
		Value: &locationValue,
	})
	priceFilters = append(priceFilters, &pricing.Filter{
		Type:  &typeTerm,
		Field: &instanceTypeKey,
		Value: &instanceTypeValue,
	})

	// make request
	productsOutput, _ := svc.GetProducts(&pricing.GetProductsInput{
		ServiceCode:   &ec2ServiceCode,
		FormatVersion: &formatVer,
		Filters:       priceFilters,
	})

	// transform
	priceData, _ := awsPricingTyper.GetTypedPricingData(*productsOutput)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OnDemandTerm

type OnDemandTerm struct {
	SKU           string
	EffectiveDate string
	OfferTermCode string
	//TermAttributes  OnDemandTermAttributes
	PriceDimensions []PriceDimension
}

type PriceDimension

type PriceDimension map[string]PriceDimensionItem

type PriceDimensionItem

type PriceDimensionItem struct {
	PricePerUnit []PricePerUnit
	Unit         string
	EndRange     string
	Description  string
	RateCode     string
	BeginRange   string
}

type PricePerUnit

type PricePerUnit map[string]float64

type PricingDocument

type PricingDocument struct {
	PublicationDate string
	SKU             string
	ServiceCode     string
	Version         string
	Product         Product
	Terms           struct {
		OnDemand map[string]OnDemandTerm
		Reserved map[string]ReservedTerm
	}
}

PricingDocument is a structure for each of the returned slice items representing each resulting product and it's accompanying pricing detail

func GetTypedPricingData

func GetTypedPricingData(getProductsOutput pricing.GetProductsOutput) (pricingData []PricingDocument, err error)

GetTypedPricingData takes the raw output from the AWS API and returns typed data in structs

type Product

type Product struct {
	ProductFamily string
	SKU           string
	Attributes    struct {
		NetworkPerformance          string
		VCPU                        string
		GPU                         string
		CapacityStatus              string
		OperatingSystem             string
		PhysicalProcessor           string
		PhysicalCores               string
		ECU                         string
		PreInstalledSw              string
		ProcessorArchitecture       string
		InstanceCapacity10xlarge    string
		InstanceCapacity16xlarge    string
		InstanceCapacity2xlarge     string
		InstanceCapacityXlarge      string
		InstanceCapacityLarge       string
		InstanceCapacity4xlarge     string
		InstanceCapacity8xlarge     string
		EnhancedNetworkingSupported string
		Storage                     string
		ClockSpeed                  string
		Tenancy                     string
		LicenseModel                string
		ServiceCode                 string
		CurrentGeneration           string
		DedicatedEbsThroughput      string
		ServiceName                 string
		InstanceType                string
		NormalizationSizeFactor     string
		ProcessorFeatures           string
		IntelAvxAvailable           string
		IntelAvx2Available          string
		IntelTurboAvailable         string
		Operation                   string
		Memory                      string
		LocationType                string
		InstanceFamily              string
		UsageType                   string
		Location                    string
	}
}

type ReservedTerm

type ReservedTerm struct {
	SKU            string
	EffectiveDate  string
	OfferTermCode  string
	TermAttributes struct {
		LeaseContractLength string
		OfferingClass       string
		PurchaseOption      string
	}
	PriceDimensions []PriceDimension
}

Jump to

Keyboard shortcuts

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