oidsman
oidsman

Reputation: 385

JSON body for putting a new item in table in AWS DynamoDB

I am trying to do a HTTP POST to put an item into a DynamoDB table (called "policy")

I am struggling to get the correct format. The item only has one key which is "PolicyNumber" and an additional item I am adding called 'Name'

My JSON is as follows:-

{\"TableName\":\"Policy\",\"Item\":
{\"PolicyNumber\":\"S\":\"10001\"},\"Name\":{\"S\":\"Test10001\"}}}

I get an error as follows (all one string obviously):-

{
"statusCode": "400",
"body": "One or more parameter values were invalid: Type mismatch for key 
PolicyNumber expected: S actual: M",
"headers": {
"Content-Type": "application/json"
}
}

If I run a GET to list items already in there I get the following response (these items added through console):-

{
"statusCode": "200",
"body": "{\"Items\":[{\"PolicyNumber\":\"12345\",\"Name\":\"Fred\"},{\"PolicyNumber\":\"78787\",\"Name\":\"Bill\"}],\"Count\":2,\"ScannedCount\":2}"
,
"headers": {
"Content-Type": "application/json"
}

}

Any help much appreciated!

Upvotes: 0

Views: 921

Answers (1)

Costin
Costin

Reputation: 3029

EDIT:

  • Solution:

Replace { "S": "10001" } by "10001" and { "S": "Test10001" } by "Test10001"

The type is implicit.

  • Old Answer:

There is a missing { after PolicyNumber. You should have this JSON:

{ "TableName": "Policy",
  "Item": {
     "PolicyNumber": { "S": "10001" },
     "Name": { "S": "Test10001" }
  }
}

Read more about AWS DynamoDB PutItem here.

Upvotes: 1

Related Questions