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

Error while using PutItem API of DynamoDB #274

Closed
diptanu opened this issue Jun 8, 2015 · 10 comments
Closed

Error while using PutItem API of DynamoDB #274

diptanu opened this issue Jun 8, 2015 · 10 comments

Comments

@diptanu
Copy link

diptanu commented Jun 8, 2015

I have a some code like this -

svc := dynamodb.New(&aws.Config{Region: "us-east-1"})
    svc.Endpoint = "http://localhost:8080"
    params := &dynamodb.PutItemInput{
        Item: map[string]*dynamodb.AttributeValue{
            "Foo": {
                S: aws.String("value"),
            },
            "Bar": {
                S: aws.String("value"),
            },
        },
        TableName: aws.String("DataBaseName"),
    }
    resp, err := svc.PutItem(params)

I get the following error - Unmarshal failed decoding JSON RPC error response invalid character 'p' after top-level value. I am running code from master of aws-sdk-go

Any pointers to what the issue is? My hunch is the parameters I am setting for the PutItem API is incomplete.

@lsegal
Copy link
Contributor

lsegal commented Jun 8, 2015

Passing LogLevel: 1, LogHTTPBody: true to your configuration should provide information on what the SDK was unable to parse.

My guess is that DynamoDB Local is generating an error and returning an invalid JSON response (probably plaintext indicating the failure).

@lsegal
Copy link
Contributor

lsegal commented Jun 8, 2015

Also note that you should not set Endpoint directly on service, use configuration instead:

svc := dynamodb.New(&aws.Config{Region: "us-east-1", Endpoint: "http://localhost:8080"})

@diptanu
Copy link
Author

diptanu commented Jun 8, 2015

Here is what I am seeing in the logs with LogLevel set to 1

---[ CANONICAL STRING  ]-----------------------------
POST
/

accept-encoding:identity
host:localhost:8080
x-amz-date:20150608T183625Z
x-amz-target:DynamoDB_20120810.PutItem

accept-encoding;host;x-amz-date;x-amz-target
2f23609c1bc208b32ac6a2a23f21b7e7d35d0b6bf5ffb6b569bba75b7b5d97d6
---[ STRING TO SIGN ]--------------------------------
AWS4-HMAC-SHA256
20150608T183625Z
20150608/us-east-1/dynamodb/aws4_request
ae1068d59cba3179e22e92ac7adf92cf42817058398596ad3a7d780dbbb05e20
-----------------------------------------------------
---[ REQUEST POST-SIGN ]-----------------------------
POST / HTTP/1.1
Host: localhost:8080
User-Agent: aws-sdk-go/0.6.1
Content-Length: 82
Accept-Encoding: identity
Authorization: AWS4-HMAC-SHA256 Credential=.../20150608/us-east-1/dynamodb/aws4_request, SignedHeaders=accept-encoding;host;x-amz-date;x-amz-target, Signature=a25d8746a5aa0d0458ef117ddf081dd48d2ec1a5e2096c38b5ffe493268d5168
Content-Type: application/x-amz-json-1.0
X-Amz-Content-Sha256: 2f23609c1bc208b32ac6a2a23f21b7e7d35d0b6bf5ffb6b569bba75b7b5d97d6
X-Amz-Date: 20150608T183625Z
X-Amz-Target: DynamoDB_20120810.PutItem

{"Item":{"Foo":{"S":"value"},"Bar":{"S":"value"}},"TableName":"DataBaseName"}
-----------------------------------------------------
---[ RESPONSE ]--------------------------------------
HTTP/1.1 404 Not Found
Content-Length: 19
Content-Type: text/plain; charset=utf-8
Date: Mon, 08 Jun 2015 18:36:25 GMT

404 page not found

-----------------------------------------------------
Unmarshal failed decoding JSON RPC error response invalid character 'p' after top-level value

@marcosnils
Copy link
Contributor

@diptanu seems like your post is going to localhost:8080 according to the Host header. Do you have a dynamodb listening there?

@diptanu
Copy link
Author

diptanu commented Jun 8, 2015

Yes it should go to localhost:8080, since I am using dynamodb local.

@marcosnils
Copy link
Contributor

@diptanu seems like something is not working with your dynamo local. What do you get if you issue a curl localhost:8080/ ?

@marcosnils
Copy link
Contributor

BTW: I'm also using dynamo local in my projects and this is how initialize my dynamo connection:

func Server() *dynamodb.DynamoDB {
        server := dynamodb.New(config.Current.DynamoConfig)                                                                                                                                                    

        return server
}

Where DynamoConfig is:

        Current.DynamoConfig = &aws.Config{Credentials: Current.DynamoAwsCredentials,
                Endpoint: Current.DynamoHost,
                Region:   Current.DynamoRegion,
        } 

You need to specify credentials even though those are fake.

@diptanu
Copy link
Author

diptanu commented Jun 8, 2015

Well, the ports were messed up, sorry I got rat-holed into believing the client was not able to parse the response from Dynamo Local. Closing this issue.

@diptanu diptanu closed this as completed Jun 8, 2015
@diptanu
Copy link
Author

diptanu commented Jun 8, 2015

@marcosnils I thought the SDK could use on-instance keys if I don't specify any credentials. It would be really nice if that's how it worked even if it doesn't work like that today.

@lsegal
Copy link
Contributor

lsegal commented Jun 8, 2015

@diptanu I would recommend opening a feature request on the Amazon DynamoDB forums if you would like to see support for anonymous access in Local.

skotambkar pushed a commit to skotambkar/aws-sdk-go that referenced this issue May 20, 2021
Breaking Change
---
* Update SDK retry behavior
  * Significant updates were made the SDK's retry behavior. The SDK will now retry all connections error. In addition, to changing what errors are retried the SDK's retry behavior not distinguish the difference between throttling errors, and regular retryable errors. All errors will be retried with the same backoff jitter delay scaling.
  * The SDK will attempt an operation request 3 times by default. This is one less than the previous initial request with 3 retires.
  * New helper functions in the new `aws/retry` package allow wrapping a `Retrier` with custom behavior, overriding the base `Retrier`, (e.g. `AddWithErrorCodes`, and `AddWithMaxAttempts`)
* Update SDK error handling
  * Updates the SDK's handling of errors to take advantage of Go 1.13's new `errors.As`, `Is`, and `Unwrap`. The SDK's errors were updated to satisfy the `Unwrap` interface, returning the underlying error.
  * With this update, you can now more easily access the SDK's layered errors, and meaningful state such as, `Timeout`, `Temporary`, and other states added to the SDK such as `CanceledError`.
* Bump SDK minimum supported version from Go 1.12 to Go 1.13
  * The SDK's minimum supported version is bumped to take advantage of Go 1.13's updated `errors` package.

Services
---
* Synced the V2 SDK with latest AWS service API definitions.

SDK Features
---
* `aws`: Add Support for additional credential providers and credential configuration chaining ([aws#488](aws/aws-sdk-go-v2#488))
  * `aws/processcreds`: Adds Support for the Process Credential Provider
    * Fixes [aws#249](aws/aws-sdk-go-v2#249)
  * `aws/stscreds`: Adds Support for the Web Identity Credential Provider
    * Fixes [aws#475](aws/aws-sdk-go-v2#475)
    * Fixes [aws#338](aws/aws-sdk-go-v2#338)
  * Adds Support for `credential_source`
    * Fixes [aws#274](aws/aws-sdk-go-v2#274)
* `aws/awserr`: Adds support for Go 1.13's `errors.Unwrap` ([aws#487](aws/aws-sdk-go-v2#487))
* `aws`: Updates SDK retry behavior ([aws#487](aws/aws-sdk-go-v2#487))
  * `aws/retry`: New package defining logic to determine if a request should be retried, and backoff.
  * `aws/ratelimit`: New package defining rate limit logic such as token bucket used by the `retry.Standard` retrier.

SDK Enhancements
---
* `aws`: Add grouping of concurrent refresh of credentials ([aws#503](aws/aws-sdk-go-v2#503))
  * Concurrent calls to `Retrieve` are now grouped in order to prevent numerous synchronous calls to refresh the credentials. Replacing the mutex with a singleflight reduces the overall amount of time request signatures need to wait while retrieving credentials. This is improvement becomes pronounced when many requests are made concurrently.
* `service/s3/s3manager`: Improve memory allocation behavior by replacing sync.Pool with custom pool implementation
  * Improves memory allocations that occur when the provided `io.Reader` to upload does not satisfy both the `io.ReaderAt` and `io.ReadSeeker` interfaces.

SDK Bugs
---
* `service/s3/s3manager`: Fix resource leaks when the following occurred:
  * Failed CreateMultipartUpload call
  * Failed UploadPart call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants