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

2
  • 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? Commented Jun 30, 2022 at 14:55
  • I added the error , apologies for the ommission. Commented Jun 30, 2022 at 15:14

1 Answer 1

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"}}'
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.