DynamoDB beginner’s guide

There are some parts of the DynamoDB documentation that may be tricky for new developers. Here I’ll attempt to explain some of them...

“has no effect”, what does that mean?

TL;DR - “has no effect” means that the result from an API call to DynamoDB with the specified settings will not include an Attributes section. This is because of the default behavior that’s called out in the docs which states: The default value for ReturnValues is NONE, meaning that DynamoDB does not return any information about attributes that were modified

The DynamoDB docs page about Working with Items uses the term “has no effect” several times when referring to how to use the different options for ReturnValues. For example (emphasis added):

PutItem
- ReturnValues: ALL_OLD

  - If you overwrite an existing item, ALL_OLD returns the entire item as it appeared before the overwrite.

  - If you write a nonexistent item, ALL_OLD has no effect.

What does this mean? Well, let’s look at some code:

result = server_table.put_item(Item={ID: id, DATA: data},
                               ReturnValues='ALL_OLD')

This code wants to put a value into the server table that has an ID value and a DATA value. The return values option is set to ALL_OLD. What will we see in the result? It depends if this call ends up overwriting an item. If there’s no item so it doesn’t overwrite anything you’ll get something like this:

{
    "ResponseMetadata": {
        "HTTPHeaders": {
            "connection": "keep-alive",
            "content-length": "2",
            "content-type": "application/x-amz-json-1.0",
            "date": "Wed, 29 Dec 2021 21:04:46 GMT",
            "server": "Server",
            "x-amz-crc32": "2745614147",
            "x-amzn-requestid": "PAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG"
        },
        "HTTPStatusCode": 200,
        "RequestId": "PAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG",
        "RetryAttempts": 0
    }
}

This is just the normal ResponseMetadata that every API call gets. If it does end up overwriting something then it might look like this:

{
    "Attributes": {
        "id": "1234",
        "data": "abcd"
    },
    "ResponseMetadata": {
        "HTTPHeaders": {
            "connection": "keep-alive",
            "content-length": "231",
            "content-type": "application/x-amz-json-1.0",
            "date": "Wed, 29 Dec 2021 21:05:14 GMT",
            "server": "Server",
            "x-amz-crc32": "3043499835",
            "x-amzn-requestid": "MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG"
        },
        "HTTPStatusCode": 200,
        "RequestId": "MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG",
        "RetryAttempts": 0
    }
}