1

I'm using the AWS CLI to make a dynamoDB query that includes key-condition-expression and expression-attribute-names and I keep getting invalid errors:

Invalid type for parameter ExpressionAttributeNames.:taskName, value: OrderedDict([(u'S', u'taskOne')]), type: <class 'collections.OrderedDict'>, valid types: <type 'basestring'>
Invalid type for parameter ExpressionAttributeNames.#status, value: OrderedDict([(u'S', u'status')]), type: <class 'collections.OrderedDict'>, valid types: <type 'basestring'>
Invalid type for parameter ExpressionAttributeNames.:status, value: OrderedDict([(u'S', u'success')]), type: <class 'collections.OrderedDict'>, valid types: <type 'basestring'>

I've looked at previous questions such as dynamodb-get-item-boto3-parameter-validation-failed and invalid-type-parameter-class-str-valid-types-class-dict but I'm not seeing what I'm doing wrong.

Dynamo calls require the attribute datatype, which I have included, but I think that's what is causing the error. Removing the datatype causes another expected error.

Heres my call:

aws dynamodb query \
    --table-name myTable \
    --key-condition-expression "taskName = :taskName AND #status = :status" \
    --expression-attribute-names '{":taskName":{"S":"taskOne"},"#status":{"S":"status"},":status":{"S":"success"}}'

UPDATE: When I remove the datatype: "S", I get this error:

Error parsing parameter '--expression-attribute-names': Invalid JSON: No JSON object could be decoded

JM Gelilio
  • 3,482
  • 1
  • 11
  • 23
johnny_mac
  • 1,801
  • 3
  • 20
  • 48
  • Could you try it without the {"s" ...} and just the String? `--expression-attribute-names '{":taskName":"taskOne","#status":"status",":status":success"}'` Or what is the the other unexpected error if you try it just with the strings? – Chris Jun 30 '22 at 14:55
  • I added the error , apologies for the ommission. – johnny_mac Jun 30 '22 at 15:14

1 Answers1

3

You're mixing attribute names and values under attribute names. You need both https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeValues.html Names are a pure string, and values are an object as you defined with the "S" as type. But both are defined separately

Try this

aws dynamodb query \
    --table-name myTable \
    --key-condition-expression "#taskName = :taskName AND #status = :status" \
    --expression-attribute-names '{"#taskName": "taskName","#status": "status"}'
    --expression-attribute-values '{":taskName":{"S":"taskOne"},":status":{"S":"success"}}'
    
karjan
  • 936
  • 1
  • 7
  • 17