Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarshalling error when calling the pricing GetProducts API #1636

Closed
justone opened this issue Nov 8, 2017 · 4 comments
Closed

Unmarshalling error when calling the pricing GetProducts API #1636

justone opened this issue Nov 8, 2017 · 4 comments
Labels
bug This issue is a bug. service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@justone
Copy link

justone commented Nov 8, 2017

Version of AWS SDK for Go?

I'm using the latest master version of the SDK.

$ git describe --tags
v1.12.24-1-g33a45e85
$ git show
commit 33a45e8502517905ddff447d5ab60d87bd8d558d (HEAD -> master, origin/master, origin/HEAD)
Merge: 262fa753 6061953e
Author: awstools <aws-dr-tools-github-user@amazon.com>
Date:   2017-11-07 13:26:45 -0800

    Merge pull request #1634 from aws/release
    
    Release v1.12.24

Version of Go (go version)?

$ go version
go version go1.9 linux/amd64

The environment is inside a Docker container, accessed via SSH.

OS is Ubuntu 16.04:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial

What issue did you see?

When I call the pricing GetProducts method, I get a serialization error.

Steps to reproduce

Using this code (almost verbatim from the example, except I had to move ServiceCode from a filter to a top level key):

package main

import (
	"fmt"

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

func main() {
	svc := pricing.New(session.New(&aws.Config{Region: aws.String("us-east-1")}))
	input := &pricing.GetProductsInput{
		ServiceCode: aws.String("AmazonEC2"),
		Filters: []*pricing.Filter{
			{
				Field: aws.String("volumeType"),
				Type:  aws.String("TERM_MATCH"),
				Value: aws.String("Provisioned IOPS"),
			},
		},
		FormatVersion: aws.String("aws_v1"),
		MaxResults:    aws.Int64(1),
	}

	result, err := svc.GetProducts(input)
	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)
}
$ go run getproducts.go 
SerializationError: failed decoding JSON RPC response
caused by: JSON value is not a map ("{\"product\":{\"productFamily\":\"Storage\",\"attributes\":{\"storageMedia\":\"SSD-backed\",\"maxThroughputvolume\":\"320 MB/sec\",\"volumeType\":\"Provisioned IOPS\",\"maxIopsvolume\":\"20000\",\"servicecode\":\"AmazonEC2\",\"usagetype\":\"APS1-EBS:VolumeUsage.piops\",\"locationType\":\"AWS Region\",\"location\":\"Asia Pacific (Singapore)\",\"servicename\":\"Amazon Elastic Compute Cloud\",\"maxVolumeSize\":\"16 TiB\",\"operation\":\"\"},\"sku\":\"3MKHN58N7RDDVGKJ\"},\"serviceCode\":\"AmazonEC2\",\"terms\":{\"OnDemand\":{\"3MKHN58N7RDDVGKJ.JRTCKXETXF\":{\"priceDimensions\":{\"3MKHN58N7RDDVGKJ.JRTCKXETXF.6YS6EN2CT7\":{\"unit\":\"GB-Mo\",\"endRange\":\"Inf\",\"description\":\"$0.138 per GB-month of Provisioned IOPS SSD (io1)  provisioned storage - Asia Pacific (Singapore)\",\"appliesTo\":[],\"rateCode\":\"3MKHN58N7RDDVGKJ.JRTCKXETXF.6YS6EN2CT7\",\"beginRange\":\"0\",\"pricePerUnit\":{\"USD\":\"0.1380000000\"}}},\"sku\":\"3MKHN58N7RDDVGKJ\",\"effectiveDate\":\"2017-10-01T00:00:00Z\",\"offerTermCode\":\"JRTCKXETXF\",\"termAttributes\":{}}}},\"version\":\"20171026015458\",\"publicationDate\":\"2017-10-26T01:54:58Z\"}")

I tried to dig into the unmarshalling code, and it looks like the data passed to the unmarshalMap function is actually a string and not a map and that causes the failure.

I don't know enough to tell if this is an error in the unmarshalling code or in the API's response.

Please let me know if I can provide any other information.

Thank you.

@jasdel jasdel added the service-api This issue is due to a problem in a service API, not the SDK implementation. label Nov 8, 2017
@jasdel
Copy link
Contributor

jasdel commented Nov 8, 2017

Thanks for reaching out to us @justone We're taking a look at this, and will update once we reproduce the issue.

@jasdel
Copy link
Contributor

jasdel commented Nov 8, 2017

Was able to reproduce this easily. Thanks for the sample.

Response body from service.

{
  "FormatVersion": "aws_v1",
  "NextToken": "nwgM6jfEMURvqUBTOCtXvw==:0x2+NWRDC5l8tzDFYdtRI7sv1ua8wr8gulXULluS8OBMjd2UvaVhWVCIOyIhZnLtefLKeduMMIcajIpmk+niXFXR0k+iKhmtLRtW528QNyUR1FrLzrbP8Zru8tJaXMvB/JJe1I3Qoc+aMeGtF0LjXNJuLFqtu6wFohQvX9RyQTGL/gQHabQbYcKmTiOGhAkh",
  "PriceList": [
    "{\"product\":{\"productFamily\":\"Storage\",\"attributes\":{\"storageMedia\":\"SSD-backed\",\"maxThroughputvolume\":\"320 MB/sec\",\"volumeType\":\"Provisioned IOPS\",\"maxIopsvolume\":\"20000\",\"servicecode\":\"AmazonEC2\",\"usagetype\":\"APS1-EBS:VolumeUsage.piops\",\"locationType\":\"AWS Region\",\"location\":\"Asia Pacific (Singapore)\",\"servicename\":\"Amazon Elastic Compute Cloud\",\"maxVolumeSize\":\"16 TiB\",\"operation\":\"\"},\"sku\":\"3MKHN58N7RDDVGKJ\"},\"serviceCode\":\"AmazonEC2\",\"terms\":{\"OnDemand\":{\"3MKHN58N7RDDVGKJ.JRTCKXETXF\":{\"priceDimensions\":{\"3MKHN58N7RDDVGKJ.JRTCKXETXF.6YS6EN2CT7\":{\"unit\":\"GB-Mo\",\"endRange\":\"Inf\",\"description\":\"$0.138 per GB-month of Provisioned IOPS SSD (io1)  provisioned storage - Asia Pacific (Singapore)\",\"appliesTo\":[],\"rateCode\":\"3MKHN58N7RDDVGKJ.JRTCKXETXF.6YS6EN2CT7\",\"beginRange\":\"0\",\"pricePerUnit\":{\"USD\":\"0.1380000000\"}}},\"sku\":\"3MKHN58N7RDDVGKJ\",\"effectiveDate\":\"2017-10-01T00:00:00Z\",\"offerTermCode\":\"JRTCKXETXF\",\"termAttributes\":{}}}},\"version\":\"20171026015458\",\"publicationDate\":\"2017-10-26T01:54:58Z\"}"
  ]
}

@jasdel jasdel added the bug This issue is a bug. label Nov 8, 2017
jasdel added a commit to jasdel/aws-sdk-go that referenced this issue Nov 9, 2017
jasdel added a commit to jasdel/aws-sdk-go that referenced this issue Nov 14, 2017
jasdel added a commit to jasdel/aws-sdk-go that referenced this issue Nov 15, 2017
jasdel added a commit that referenced this issue Nov 17, 2017
…uerystring (#1640)

Adds support for APIs which use JSONValue for body and querystring targets.

Fix #1636
@jasdel
Copy link
Contributor

jasdel commented Nov 17, 2017

Thanks for reporting this issue @justone I've merged in a fix that will correct the SDK's behavior. This will be included in the next release.

@justone
Copy link
Author

justone commented Nov 17, 2017

Awesome, @jasdel, thanks for fixing it up!

@awstools awstools mentioned this issue Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants