2

Here's my use case, I need to add and update entries in a DynamoDB table like this:

If the partition key doesn't exist, add it and add a new one element list containing a string value. If the partition key does exist, add a new string to its list attribute. I have code that Python/boto3 looks like this:

response = ddb_client.update_item(
    TableName=target_ddb_table,
    Key={'email-hash': {'S' : encrypted_hashed_pw},},
    ExpressionAttributeValues={ ":my_value":[{"S":"test"}], ":empty_list":[] },
    UpdateExpression='SET site_ids = list_append(if_not_exists(site_ids, :empty_list), :my_value)',
    ReturnValues='ALL_NEW'
)

I'm getting these errors, I realize that I'm doing something dumb here:re

Invalid type for parameter ExpressionAttributeValues.:empty_list, value: [], type: <class 'list'>, valid types: <class 'dict'>
Invalid type for parameter ExpressionAttributeValues.:my_value, value: [{'S': 'test'}], type: <class 'list'>, valid types: <class 'dict'>

1 Answer 1

2

Figured it out, I need to add the type info for the Lists:

":my_value": {"L": [{"S": "test"}]}, ":empty_list": {"L": []}
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.