JuliaCloud / AWS.jl

Julia interface to AWS
MIT License
159 stars 62 forks source link

DynamoDB Query service returns "Unexpected field type" #673

Closed theanhhoang closed 2 months ago

theanhhoang commented 2 months ago

Hi, I am trying to use the DynamoDB query for a while but it keeps returning ERROR: AWS.AWSExceptions.AWSException: SerializationException -- Unexpected field type. Can you please assist with that error?

Here is what I have tried with aws-cli, which was able to obtain the response:

    aws dynamodb query \
        --table-name my-dynamo-table \
        --key-condition-expression "#pk = :val" \
        --expression-attribute-names '{"#pk": "_pkID"}' \
        --expression-attribute-values '{":val":{"S":"myObject"}}'

and here is what I am testing in Julia:

    data = DYNAMO_CLIENT.query("my-dynamo-table", Dict(
        "KeyConditionExpression" => "#pk = :val",
        "ExpressionAttributeNames" => "{\"#pk\" : \"_pkID\"}",
        "ExpressionAttributeValues" => "{\":val\": {\"S\":\"myObject\"}}"
        )
    )

and the error looks like this: Screenshot 2024-05-28 at 10 06 17 AM

ericphanson commented 2 months ago

Maybe try:

    data = DYNAMO_CLIENT.query("my-dynamo-table", Dict(
        "KeyConditionExpression" => "#pk = :val",
        "ExpressionAttributeNames" => Dict("#pk"  => "_pkID"),
        "ExpressionAttributeValues" => Dict(":val" => Dict( "S" => "myObject"))
        )
    )

since it could be the Julia code expects the serialize the json itself. Not sure.

theanhhoang commented 2 months ago

Thanks Eric, that's truly the solution. Will close this issue ticket but I think the documentation needs to be updated to avoid mistake like me.