pricing

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: Apache-2.0 Imports: 7 Imported by: 44

Documentation

Overview

Package pricing provides the client and types for making API requests to AWS Pricing.

AWS Price List Service API (AWS Price List Service) is a centralized and convenient way to programmatically query Amazon Web Services for services, products, and pricing information. The AWS Price List Service uses standardized product attributes such as Location, Storage Class, and Operating System, and provides prices at the SKU level. You can use the AWS Price List Service to build cost control and scenario planning tools, reconcile billing data, forecast future spend for budgeting purposes, and provide cost benefit analysis that compare your internal workloads with AWS.

Use GetServices without a service code to retrieve the service codes for all AWS services, then GetServices with a service code to retreive the attribute names for that service. After you have the service code and attribute names, you can use GetAttributeValues to see what values are available for an attribute. With the service code and an attribute name and value, you can use GetProducts to find specific products that you're interested in, such as an AmazonEC2 instance, with a Provisioned IOPS volumeType.

Service Endpoint

AWS Price List Service API provides the following two endpoints:

See https://docs.aws.amazon.com/goto/WebAPI/pricing-2017-10-15 for more information on this service.

See pricing package documentation for more information. https://docs.aws.amazon.com/sdk-for-go/api/service/pricing/

Using the Client

To use AWS Pricing with the SDK use the New function to create a new service client. With that client you can make API requests to the service. These clients are safe to use concurrently.

See the SDK's documentation for more information on how to use the SDK. https://docs.aws.amazon.com/sdk-for-go/api/

See aws.Config documentation for more information on configuring SDK clients. https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config

See the AWS Pricing client for more information on creating client for this service. https://docs.aws.amazon.com/sdk-for-go/api/service/pricing/#New

Index

Examples

Constants

View Source
const (
	ServiceName = "AWS Pricing" // Service's name
	ServiceID   = "Pricing"     // Service's identifier
	EndpointsID = "api.pricing" // Service's Endpoint identifier
)
View Source
const (

	// ErrCodeExpiredNextTokenException for service response error code
	// "ExpiredNextTokenException".
	//
	// The pagination token expired. Try again without a pagination token.
	ErrCodeExpiredNextTokenException = "ExpiredNextTokenException"

	// ErrCodeInternalErrorException for service response error code
	// "InternalErrorException".
	//
	// An error on the server occurred during the processing of your request. Try
	// again later.
	ErrCodeInternalErrorException = "InternalErrorException"

	// ErrCodeInvalidNextTokenException for service response error code
	// "InvalidNextTokenException".
	//
	// The pagination token is invalid. Try again without a pagination token.
	ErrCodeInvalidNextTokenException = "InvalidNextTokenException"

	// ErrCodeInvalidParameterException for service response error code
	// "InvalidParameterException".
	//
	// One or more parameters had an invalid value.
	ErrCodeInvalidParameterException = "InvalidParameterException"

	// ErrCodeNotFoundException for service response error code
	// "NotFoundException".
	//
	// The requested resource can't be found.
	ErrCodeNotFoundException = "NotFoundException"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributeValue

type AttributeValue struct {

	// The specific value of an attributeName.
	Value *string `type:"string"`
	// contains filtered or unexported fields
}

The values of a given attribute, such as Throughput Optimized HDD or Provisioned IOPS for the Amazon EC2 volumeType attribute.

func (AttributeValue) String

func (s AttributeValue) String() string

String returns the string representation

type Client added in v0.9.0

type Client struct {
	*aws.Client
}

Client provides the API operation methods for making requests to AWS Pricing. See this package's package overview docs for details on the service.

The client's methods are safe to use concurrently. It is not safe to modify mutate any of the struct's properties though.

func New

func New(config aws.Config) *Client

New creates a new instance of the client from the provided Config.

Example:

// Create a client from just a config.
svc := pricing.New(myConfig)

func (*Client) DescribeServicesRequest added in v0.9.0

func (c *Client) DescribeServicesRequest(input *DescribeServicesInput) DescribeServicesRequest

DescribeServicesRequest returns a request value for making API operation for AWS Price List Service.

Returns the metadata for one service or a list of the metadata for all services. Use this without a service code to get the service codes for all services. Use it with a service code, such as AmazonEC2, to get information specific to that service, such as the attribute names available for that service. For example, some of the attribute names available for EC2 are volumeType, maxIopsVolume, operation, locationType, and instanceCapacity10xlarge.

// Example sending a request using DescribeServicesRequest.
req := client.DescribeServicesRequest(params)
resp, err := req.Send(context.TODO())
if err == nil {
    fmt.Println(resp)
}

Please also see https://docs.aws.amazon.com/goto/WebAPI/pricing-2017-10-15/DescribeServices

Example (Shared00)
package main

import (
	"context"
	"fmt"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/aws/awserr"
	"github.com/aws/aws-sdk-go-v2/aws/external"
	"github.com/aws/aws-sdk-go-v2/service/pricing"
)

func main() {
	cfg, err := external.LoadDefaultAWSConfig()
	if err != nil {
		panic("failed to load config, " + err.Error())
	}

	svc := pricing.New(cfg)
	input := &pricing.DescribeServicesInput{
		FormatVersion: aws.String("aws_v1"),
		MaxResults:    aws.Int64(1),
		ServiceCode:   aws.String("AmazonEC2"),
	}

	req := svc.DescribeServicesRequest(input)
	result, err := req.Send(context.Background())
	if err != nil {
		if aerr, ok := err.(awserr.Error); ok {
			switch aerr.Code() {
			case pricing.ErrCodeInternalErrorException:
				fmt.Println(pricing.ErrCodeInternalErrorException, aerr.Error())
			case pricing.ErrCodeInvalidParameterException:
				fmt.Println(pricing.ErrCodeInvalidParameterException, aerr.Error())
			case pricing.ErrCodeNotFoundException:
				fmt.Println(pricing.ErrCodeNotFoundException, aerr.Error())
			case pricing.ErrCodeInvalidNextTokenException:
				fmt.Println(pricing.ErrCodeInvalidNextTokenException, aerr.Error())
			case pricing.ErrCodeExpiredNextTokenException:
				fmt.Println(pricing.ErrCodeExpiredNextTokenException, aerr.Error())
			default:
				fmt.Println(aerr.Error())
			}
		} else {
			// Print the error, cast err to awserr.Error to get the Code and
			// Message from an error.
			fmt.Println(err.Error())
		}
		return
	}

	fmt.Println(result)
}
Output:

func (*Client) GetAttributeValuesRequest added in v0.9.0

func (c *Client) GetAttributeValuesRequest(input *GetAttributeValuesInput) GetAttributeValuesRequest

GetAttributeValuesRequest returns a request value for making API operation for AWS Price List Service.

Returns a list of attribute values. Attibutes are similar to the details in a Price List API offer file. For a list of available attributes, see Offer File Definitions (http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/reading-an-offer.html#pps-defs) in the AWS Billing and Cost Management User Guide (http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-what-is.html).

// Example sending a request using GetAttributeValuesRequest.
req := client.GetAttributeValuesRequest(params)
resp, err := req.Send(context.TODO())
if err == nil {
    fmt.Println(resp)
}

Please also see https://docs.aws.amazon.com/goto/WebAPI/pricing-2017-10-15/GetAttributeValues

Example (Shared00)

To retrieve a list of attribute values

This operation returns a list of values available for the given attribute.

package main

import (
	"context"
	"fmt"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/aws/awserr"
	"github.com/aws/aws-sdk-go-v2/aws/external"
	"github.com/aws/aws-sdk-go-v2/service/pricing"
)

func main() {
	cfg, err := external.LoadDefaultAWSConfig()
	if err != nil {
		panic("failed to load config, " + err.Error())
	}

	svc := pricing.New(cfg)
	input := &pricing.GetAttributeValuesInput{
		AttributeName: aws.String("volumeType"),
		MaxResults:    aws.Int64(2),
		ServiceCode:   aws.String("AmazonEC2"),
	}

	req := svc.GetAttributeValuesRequest(input)
	result, err := req.Send(context.Background())
	if err != nil {
		if aerr, ok := err.(awserr.Error); ok {
			switch aerr.Code() {
			case pricing.ErrCodeInternalErrorException:
				fmt.Println(pricing.ErrCodeInternalErrorException, aerr.Error())
			case pricing.ErrCodeInvalidParameterException:
				fmt.Println(pricing.ErrCodeInvalidParameterException, aerr.Error())
			case pricing.ErrCodeNotFoundException:
				fmt.Println(pricing.ErrCodeNotFoundException, aerr.Error())
			case pricing.ErrCodeInvalidNextTokenException:
				fmt.Println(pricing.ErrCodeInvalidNextTokenException, aerr.Error())
			case pricing.ErrCodeExpiredNextTokenException:
				fmt.Println(pricing.ErrCodeExpiredNextTokenException, aerr.Error())
			default:
				fmt.Println(aerr.Error())
			}
		} else {
			// Print the error, cast err to awserr.Error to get the Code and
			// Message from an error.
			fmt.Println(err.Error())
		}
		return
	}

	fmt.Println(result)
}
Output:

func (*Client) GetProductsRequest added in v0.9.0

func (c *Client) GetProductsRequest(input *GetProductsInput) GetProductsRequest

GetProductsRequest returns a request value for making API operation for AWS Price List Service.

Returns a list of all products that match the filter criteria.

// Example sending a request using GetProductsRequest.
req := client.GetProductsRequest(params)
resp, err := req.Send(context.TODO())
if err == nil {
    fmt.Println(resp)
}

Please also see https://docs.aws.amazon.com/goto/WebAPI/pricing-2017-10-15/GetProducts

Example (Shared00)

To retrieve a list of products

This operation returns a list of products that match the given criteria.

package main

import (
	"context"
	"fmt"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/aws/awserr"
	"github.com/aws/aws-sdk-go-v2/aws/external"
	"github.com/aws/aws-sdk-go-v2/service/pricing"
)

func main() {
	cfg, err := external.LoadDefaultAWSConfig()
	if err != nil {
		panic("failed to load config, " + err.Error())
	}

	svc := pricing.New(cfg)
	input := &pricing.GetProductsInput{
		Filters: []pricing.Filter{
			{
				Field: aws.String("ServiceCode"),
				Type:  pricing.FilterTypeTermMatch,
				Value: aws.String("AmazonEC2"),
			},
			{
				Field: aws.String("volumeType"),
				Type:  pricing.FilterTypeTermMatch,
				Value: aws.String("Provisioned IOPS"),
			},
		},
		FormatVersion: aws.String("aws_v1"),
		MaxResults:    aws.Int64(1),
	}

	req := svc.GetProductsRequest(input)
	result, err := req.Send(context.Background())
	if err != nil {
		if aerr, ok := err.(awserr.Error); ok {
			switch aerr.Code() {
			case pricing.ErrCodeInternalErrorException:
				fmt.Println(pricing.ErrCodeInternalErrorException, aerr.Error())
			case pricing.ErrCodeInvalidParameterException:
				fmt.Println(pricing.ErrCodeInvalidParameterException, aerr.Error())
			case pricing.ErrCodeNotFoundException:
				fmt.Println(pricing.ErrCodeNotFoundException, aerr.Error())
			case pricing.ErrCodeInvalidNextTokenException:
				fmt.Println(pricing.ErrCodeInvalidNextTokenException, aerr.Error())
			case pricing.ErrCodeExpiredNextTokenException:
				fmt.Println(pricing.ErrCodeExpiredNextTokenException, aerr.Error())
			default:
				fmt.Println(aerr.Error())
			}
		} else {
			// Print the error, cast err to awserr.Error to get the Code and
			// Message from an error.
			fmt.Println(err.Error())
		}
		return
	}

	fmt.Println(result)
}
Output:

type DescribeServicesInput

type DescribeServicesInput struct {

	// The format version that you want the response to be in.
	//
	// Valid values are: aws_v1
	FormatVersion *string `type:"string"`

	// The maximum number of results that you want returned in the response.
	MaxResults *int64 `min:"1" type:"integer"`

	// The pagination token that indicates the next set of results that you want
	// to retrieve.
	NextToken *string `type:"string"`

	// The code for the service whose information you want to retrieve, such as
	// AmazonEC2. You can use the ServiceCode to filter the results in a GetProducts
	// call. To retrieve a list of all services, leave this blank.
	ServiceCode *string `type:"string"`
	// contains filtered or unexported fields
}

func (DescribeServicesInput) String

func (s DescribeServicesInput) String() string

String returns the string representation

func (*DescribeServicesInput) Validate

func (s *DescribeServicesInput) Validate() error

Validate inspects the fields of the type to determine if they are valid.

type DescribeServicesOutput

type DescribeServicesOutput struct {

	// The format version of the response. For example, aws_v1.
	FormatVersion *string `type:"string"`

	// The pagination token for the next set of retreivable results.
	NextToken *string `type:"string"`

	// The service metadata for the service or services in the response.
	Services []Service `type:"list"`
	// contains filtered or unexported fields
}

func (DescribeServicesOutput) String

func (s DescribeServicesOutput) String() string

String returns the string representation

type DescribeServicesPaginator added in v0.9.0

type DescribeServicesPaginator struct {
	aws.Pager
}

DescribeServicesPaginator is used to paginate the request. This can be done by calling Next and CurrentPage.

func NewDescribeServicesPaginator added in v0.9.0

func NewDescribeServicesPaginator(req DescribeServicesRequest) DescribeServicesPaginator

NewDescribeServicesRequestPaginator returns a paginator for DescribeServices. Use Next method to get the next page, and CurrentPage to get the current response page from the paginator. Next will return false, if there are no more pages, or an error was encountered.

Note: This operation can generate multiple requests to a service.

// Example iterating over pages.
req := client.DescribeServicesRequest(input)
p := pricing.NewDescribeServicesRequestPaginator(req)

for p.Next(context.TODO()) {
    page := p.CurrentPage()
}

if err := p.Err(); err != nil {
    return err
}

func (*DescribeServicesPaginator) CurrentPage added in v0.9.0

type DescribeServicesRequest

type DescribeServicesRequest struct {
	*aws.Request
	Input *DescribeServicesInput
	Copy  func(*DescribeServicesInput) DescribeServicesRequest
}

DescribeServicesRequest is the request type for the DescribeServices API operation.

func (DescribeServicesRequest) Send

Send marshals and sends the DescribeServices API request.

type DescribeServicesResponse added in v0.9.0

type DescribeServicesResponse struct {
	*DescribeServicesOutput
	// contains filtered or unexported fields
}

DescribeServicesResponse is the response type for the DescribeServices API operation.

func (*DescribeServicesResponse) SDKResponseMetdata added in v0.9.0

func (r *DescribeServicesResponse) SDKResponseMetdata() *aws.Response

SDKResponseMetdata returns the response metadata for the DescribeServices request.

type Filter

type Filter struct {

	// The product metadata field that you want to filter on. You can filter by
	// just the service code to see all products for a specific service, filter
	// by just the attribute name to see a specific attribute for multiple services,
	// or use both a service code and an attribute name to retrieve only products
	// that match both fields.
	//
	// Valid values include: ServiceCode, and all attribute names
	//
	// For example, you can filter by the AmazonEC2 service code and the volumeType
	// attribute name to get the prices for only Amazon EC2 volumes.
	//
	// Field is a required field
	Field *string `type:"string" required:"true"`

	// The type of filter that you want to use.
	//
	// Valid values are: TERM_MATCH. TERM_MATCH returns only products that match
	// both the given filter field and the given value.
	//
	// Type is a required field
	Type FilterType `type:"string" required:"true" enum:"true"`

	// The service code or attribute value that you want to filter by. If you are
	// filtering by service code this is the actual service code, such as AmazonEC2.
	// If you are filtering by attribute name, this is the attribute value that
	// you want the returned products to match, such as a Provisioned IOPS volume.
	//
	// Value is a required field
	Value *string `type:"string" required:"true"`
	// contains filtered or unexported fields
}

The constraints that you want all returned products to match.

func (Filter) String

func (s Filter) String() string

String returns the string representation

func (*Filter) Validate

func (s *Filter) Validate() error

Validate inspects the fields of the type to determine if they are valid.

type FilterType

type FilterType string
const (
	FilterTypeTermMatch FilterType = "TERM_MATCH"
)

Enum values for FilterType

func (FilterType) MarshalValue added in v0.3.0

func (enum FilterType) MarshalValue() (string, error)

func (FilterType) MarshalValueBuf added in v0.3.0

func (enum FilterType) MarshalValueBuf(b []byte) ([]byte, error)

type GetAttributeValuesInput

type GetAttributeValuesInput struct {

	// The name of the attribute that you want to retrieve the values for, such
	// as volumeType.
	//
	// AttributeName is a required field
	AttributeName *string `type:"string" required:"true"`

	// The maximum number of results to return in response.
	MaxResults *int64 `min:"1" type:"integer"`

	// The pagination token that indicates the next set of results that you want
	// to retrieve.
	NextToken *string `type:"string"`

	// The service code for the service whose attributes you want to retrieve. For
	// example, if you want the retrieve an EC2 attribute, use AmazonEC2.
	//
	// ServiceCode is a required field
	ServiceCode *string `type:"string" required:"true"`
	// contains filtered or unexported fields
}

func (GetAttributeValuesInput) String

func (s GetAttributeValuesInput) String() string

String returns the string representation

func (*GetAttributeValuesInput) Validate

func (s *GetAttributeValuesInput) Validate() error

Validate inspects the fields of the type to determine if they are valid.

type GetAttributeValuesOutput

type GetAttributeValuesOutput struct {

	// The list of values for an attribute. For example, Throughput Optimized HDD
	// and Provisioned IOPS are two available values for the AmazonEC2 volumeType.
	AttributeValues []AttributeValue `type:"list"`

	// The pagination token that indicates the next set of results to retrieve.
	NextToken *string `type:"string"`
	// contains filtered or unexported fields
}

func (GetAttributeValuesOutput) String

func (s GetAttributeValuesOutput) String() string

String returns the string representation

type GetAttributeValuesPaginator added in v0.9.0

type GetAttributeValuesPaginator struct {
	aws.Pager
}

GetAttributeValuesPaginator is used to paginate the request. This can be done by calling Next and CurrentPage.

func NewGetAttributeValuesPaginator added in v0.9.0

func NewGetAttributeValuesPaginator(req GetAttributeValuesRequest) GetAttributeValuesPaginator

NewGetAttributeValuesRequestPaginator returns a paginator for GetAttributeValues. Use Next method to get the next page, and CurrentPage to get the current response page from the paginator. Next will return false, if there are no more pages, or an error was encountered.

Note: This operation can generate multiple requests to a service.

// Example iterating over pages.
req := client.GetAttributeValuesRequest(input)
p := pricing.NewGetAttributeValuesRequestPaginator(req)

for p.Next(context.TODO()) {
    page := p.CurrentPage()
}

if err := p.Err(); err != nil {
    return err
}

func (*GetAttributeValuesPaginator) CurrentPage added in v0.9.0

type GetAttributeValuesRequest

type GetAttributeValuesRequest struct {
	*aws.Request
	Input *GetAttributeValuesInput
	Copy  func(*GetAttributeValuesInput) GetAttributeValuesRequest
}

GetAttributeValuesRequest is the request type for the GetAttributeValues API operation.

func (GetAttributeValuesRequest) Send

Send marshals and sends the GetAttributeValues API request.

type GetAttributeValuesResponse added in v0.9.0

type GetAttributeValuesResponse struct {
	*GetAttributeValuesOutput
	// contains filtered or unexported fields
}

GetAttributeValuesResponse is the response type for the GetAttributeValues API operation.

func (*GetAttributeValuesResponse) SDKResponseMetdata added in v0.9.0

func (r *GetAttributeValuesResponse) SDKResponseMetdata() *aws.Response

SDKResponseMetdata returns the response metadata for the GetAttributeValues request.

type GetProductsInput

type GetProductsInput struct {

	// The list of filters that limit the returned products. only products that
	// match all filters are returned.
	Filters []Filter `type:"list"`

	// The format version that you want the response to be in.
	//
	// Valid values are: aws_v1
	FormatVersion *string `type:"string"`

	// The maximum number of results to return in the response.
	MaxResults *int64 `min:"1" type:"integer"`

	// The pagination token that indicates the next set of results that you want
	// to retrieve.
	NextToken *string `type:"string"`

	// The code for the service whose products you want to retrieve.
	ServiceCode *string `type:"string"`
	// contains filtered or unexported fields
}

func (GetProductsInput) String

func (s GetProductsInput) String() string

String returns the string representation

func (*GetProductsInput) Validate

func (s *GetProductsInput) Validate() error

Validate inspects the fields of the type to determine if they are valid.

type GetProductsOutput

type GetProductsOutput struct {

	// The format version of the response. For example, aws_v1.
	FormatVersion *string `type:"string"`

	// The pagination token that indicates the next set of results to retrieve.
	NextToken *string `type:"string"`

	// The list of products that match your filters. The list contains both the
	// product metadata and the price information.
	PriceList []aws.JSONValue `type:"list"`
	// contains filtered or unexported fields
}

func (GetProductsOutput) String

func (s GetProductsOutput) String() string

String returns the string representation

type GetProductsPaginator added in v0.9.0

type GetProductsPaginator struct {
	aws.Pager
}

GetProductsPaginator is used to paginate the request. This can be done by calling Next and CurrentPage.

func NewGetProductsPaginator added in v0.9.0

func NewGetProductsPaginator(req GetProductsRequest) GetProductsPaginator

NewGetProductsRequestPaginator returns a paginator for GetProducts. Use Next method to get the next page, and CurrentPage to get the current response page from the paginator. Next will return false, if there are no more pages, or an error was encountered.

Note: This operation can generate multiple requests to a service.

// Example iterating over pages.
req := client.GetProductsRequest(input)
p := pricing.NewGetProductsRequestPaginator(req)

for p.Next(context.TODO()) {
    page := p.CurrentPage()
}

if err := p.Err(); err != nil {
    return err
}

func (*GetProductsPaginator) CurrentPage added in v0.9.0

func (p *GetProductsPaginator) CurrentPage() *GetProductsOutput

type GetProductsRequest

type GetProductsRequest struct {
	*aws.Request
	Input *GetProductsInput
	Copy  func(*GetProductsInput) GetProductsRequest
}

GetProductsRequest is the request type for the GetProducts API operation.

func (GetProductsRequest) Send

Send marshals and sends the GetProducts API request.

type GetProductsResponse added in v0.9.0

type GetProductsResponse struct {
	*GetProductsOutput
	// contains filtered or unexported fields
}

GetProductsResponse is the response type for the GetProducts API operation.

func (*GetProductsResponse) SDKResponseMetdata added in v0.9.0

func (r *GetProductsResponse) SDKResponseMetdata() *aws.Response

SDKResponseMetdata returns the response metadata for the GetProducts request.

type Service

type Service struct {

	// The attributes that are available for this service.
	AttributeNames []string `type:"list"`

	// The code for the AWS service.
	ServiceCode *string `type:"string"`
	// contains filtered or unexported fields
}

The metadata for a service, such as the service code and available attribute names.

func (Service) String

func (s Service) String() string

String returns the string representation

Directories

Path Synopsis
Package pricingiface provides an interface to enable mocking the AWS Price List Service service client for testing your code.
Package pricingiface provides an interface to enable mocking the AWS Price List Service service client for testing your code.

Jump to

Keyboard shortcuts

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