Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid type for AWS DynamoDB put-item via CLI (unicode v. dict)

I would like to add an item to my DynamoDB table via command line, but I've run into a type error.

The data that I'm trying to add is very simple:

{   "id": "1" } 

The command I'm running is equally simple:

aws dynamodb put-item --table-name my_table --item '{ "id": "1" }' 

The error I'm getting is:

Invalid type for parameter Item.id, value: 1, type: <type 'unicode'>, valid types: <type 'dict'> 

I come from a JavaScript background, so I'm not familiar with dict types. From what I understand from some of the sources I've read, this is a Python thing? How do I change my data into something that DynamoDB can handle?

like image 666
samcorcos Avatar asked Dec 03 '16 23:12

samcorcos


People also ask

Which of the data type is not supported by DynamoDB?

Unlike conventional relational databases, DynamoDB does not natively support a date and time data type. It can be useful instead to store data and time data as a number data type, using Unix epoch time.

How do I add items to DynamoDB?

In Amazon DynamoDB, you can use either the DynamoDB API, or PartiQL, a SQL-compatible query language, to add an item to a table. With the DynamoDB API, you use the PutItem operation to add an item to a table. The primary key for this table consists of Artist and SongTitle. You must specify values for these attributes.

What encoding does DynamoDB use?

DynamoDB supports UTF-8 binary encoded strings which length is limited by the maximum item size which is 400 KB. If String is used as primary key, then the length of it is limited to 2048 bytes for single key and 1024 bytes for composite key.

What data types are valid for primary key of a DynamoDB table?

Each primary key attribute must be a scalar (meaning that it can hold only a single value). The only data types allowed for primary key attributes are string, number, or binary. There are no such restrictions for other, non-key attributes.


1 Answers

you need to add the type information (I assume String here)

aws dynamodb put-item --table-name my_table --item '{ "id": {"S": "1" } }' 
like image 134
hellomichibye Avatar answered Sep 22 '22 13:09

hellomichibye