I have a very simple piece of code to get an item by key. But still it does not run and gives me a ValidationException with schema nil and schema 400.
It is based on the example in godoc, but ...
code snippet:
svc := dynamodb.New(nil)
req := &dynamodb.GetItemInput {
TableName: aws.String("groups"),
Key: &map[string]*dynamodb.AttributeValue {
"Key": &dynamodb.AttributeValue {
S: aws.String("rlcomte"),
},
},
}
fmt.Println(awsutil.StringValue(req))
resp, err := svc.GetItem(req)
LogErrorIf(err)
rw.Write([]byte(awsutil.StringValue(resp)))
Hi @rlcomte could you post your wirelogs of this request by modifying your dynamodb service initialization like the following:
svc := dynamodb.New(&aws.Config{LogLevel: 1})
If the error is ValidationException: The provided key element does not match the schema This implies that there is information missing in the GetItemInput.
Was the groups table created with Key as the Hash Key, and does the groups table also have a Range Key? If the table has a range key in addition to a hash key both must be specified.
I will make the changes for the logging asap.
I did check the table hash/range key, and the table I try to access only uses a hash.
I also tried the ProjectionExpression stuff, to see if that matters, but that threw some other errors.
Hi @jasdel, I ran the service with the additional logging. Below you see the full trace. Some auth stuff is removed.
---[ CANONICAL STRING ]-----------------------------
POST
/
accept-encoding:identity
host:dynamodb.eu-west-1.amazonaws.com
x-amz-date:20150526T062318Z
x-amz-target:DynamoDB_20120810.GetItem
accept-encoding;host;x-amz-date;x-amz-target
6e68c5e4245cc293c96ac7a8cd97e5dd64ba8873f5a19a118c5fed5102bbf9d6
---[ REQUEST POST-SIGN ]-----------------------------
POST / HTTP/1.1
Host: dynamodb.eu-west-1.amazonaws.com
User-Agent: aws-sdk-go/0.5.0
Content-Length: 52
Accept-Encoding: identity
Content-Type: application/x-amz-json-1.0
X-Amz-Date: 20150526T062318Z
X-Amz-Target: DynamoDB_20120810.GetItem
---[ RESPONSE ]--------------------------------------
HTTP/1.1 400 Bad Request
Content-Length: 0
Content-Type: application/x-amz-json-1.0
Date: Tue, 26 May 2015 06:23:18 GMT
X-Amz-Crc32: 3485231410
X-Amzn-Requestid: KIAQ8PO2E7NI9MC68FDADN6SOJVV4KQNSO5AEMVJF66Q9ASUAAJG
ValidationException The provided key element does not match the schema
ValidationException The provided key element does not match the schema 400
Hmm, I checked again and it was a typo at my side ;(.
Thanks for the help.
Rine
Glad you got it working!
@jasdel How is the AWS console able to do a query just on the HASH key then?
Hi @pungoyal the AWS Console allows querying tables with a primary key (aka hash key), and optionally an additional sort key value. Under the hood the AWS console will build DynamoDB requests internally to query for record with that key.
@jasdel so you are saying query with the hash key is not a public method, but DynamoDB is 'cheating' to enable that on the AWS console? 馃
@pungoyal Sorry I think I miss understood your question. Are you looking for how does the AWS Console query for items in a DynamoDB table using a hash key? Query is how this would be done. Sorry for confusion, when I said internal i meant internal to the AWS Console's webpage logic. not an internal API.