0

I am facing problem in downloading the Data from DynamoDB. I tried with Python SDK as well as with the AWS CLI (aws dynamodb scan --table-name Alarms) but every time, I am getting the same problem. Does anyone have any idea that what is the cause for that.

Output Get

    {
        "FRE": {
            "S": "1"
        },
        "MB": {
            "S": "0"
        },
        "TW": {
            "S": "1"
        },
        "FNB": {
            "S": "0"
        },
        "Date": {
            "S": "2016-10-19 09:04:47.083456"
        },
        "TD2": {
            "S": "1"
        },
        "TD1": {
            "S": "1"
        },
        "TB": {
            "S": "1"
        }
    }

Output Required

    {
         "Date": {
            "S": "2016-10-19 09:04:47.083456"
        },

        "FRE": {
            "S": "1"
        },
        "MB": {
            "S": "0"
        },
        "TW": {
            "S": "1"
        },
        "FNB": {
            "S": "0"
        },
        "TD2": {
            "S": "1"
        },
        "TD1": {
            "S": "1"
        },
        "TB": {
            "S": "1"
        }
    }

Thanks Waqas Ali Khan

  • Not real sure what you're asking, but if you're wanting to sort scan results form DynamoDB see http://stackoverflow.com/q/9297326/1428388 – jzonthemtn Oct 19 '16 at 13:45

1 Answers1

0

When you creating dictionary object, that having problem of to maintain order, it doesn't iterate in order with respect to element added in it.

#So we have to create Ordered dict you can use collection package as follow's 

from collections import OrderedDict
data_dict = OrderedDict() 
data_dict["Date"] = {'S': '2016-10-19 09:04:47.083456'}
data_dict["FRE"] = {'S': '1'}
data_dict["MB"] = {'S': '0'}
data_dict["TW"] = {'S': '1'}
data_dict["FNB"] = {'S': '0'}
data_dict["TD2"] = {'S': '1'}
data_dict["TD1"] = {'S': '1'}
data_dict["TB"] = {'S': '1'}

output:
#It maintain order of data inserted:
print data_dict
OrderedDict([('Date', {'S': '2016-10-19 09:04:47.083456'}), ('FRE', {'S': '1'}), ('MB', {'S': '0'}), ('TW', {'S': '1'}), ('FNB', {'S': '0'}), ('TD2', {'S': '1'}), ('TD1', {'S': '1'}), ('TB', {'S': '1'})])

Now, you will maintain order of your directory, in sequence of data added in it. you can able to iterate in order also.

Prafull kadam
  • 208
  • 1
  • 6