How can I use AWS's Dynamo Db with Django? How can I use AWS's Dynamo Db with Django? django django

How can I use AWS's Dynamo Db with Django?


As written by others, Django does not have NoSQL DBMS. There are third-party packages, but given the flexible nature of NoSQL data, no ‘ready-made batteries’, as @slajma said.

PynamoDB seems fine, I never used it, so I can’t recommend. In all use-cases I came across boto3 was sufficient. Setup is pretty simple, but the devil is in details (in the data structure and how nested it is, to be precise). Basically, three steps are needed:

  1. connect with db and perform operation you want (boto3)
  2. parse incoming data into Python dictionary (e.g. with dynamodb-json, boto3.dynamodb.types.TypeDeserializer or you can build your own)
  3. do business logic, store data into relational db using Django ORM or whatever you need

Simplest example:

from dynamodb_json import json_util as dynamodb_jsonfrom .models import YourModeldef get(request, partition_key):    table = boto3.resource(        'dynamodb',        aws_access_key_id=...,        aws_secret_access_key=...,        region_name=...,    ).Table(some_table_name)    try:        response = table.get_item(            Key={partition_key: partition_key})    except ClientError as e:        logger.warning(e.response['Error']['Message'])    else:        data_str = response['Item']        _data_dict = dynamodb_json.loads(data_str)        # Validation and modification of incoming data goes here.        data_dict = validation_and_modification(_data_dict)        # Then you can do whatever you need, for example:        obj, created = YourModel.objects.update_or_create(**data_dict)        ...

Hope this helps someone. Examples for create, delete, list and update views can be found in the serverless repo.


It's not like ready made battery for django, but worth looking at it regardless.https://github.com/pynamodb/PynamoDB


You can try Dynamorm or pynamoDB. I haven't tried them maybe they can help.