0

If user enters an attribute that does not exist in Dynamodb, accept the attribute and store into Dynamodb.

Currently, I have 'id' and 'firstName' as the attributes and user can create by inserting their firstName however, if they want to add a 'lastName' attribute, dynamodb should accept the 'lastName' and store into the database.

def create(event):
    body = dict(event['body'])
    id = body['id']
    firstName = body['firstName']

    response = table.put_item(
        Item={
            'id': str(id),
            'firstName': firstName,
        },
    )
1
  • 1
    Hi, your post does not include a question. You should clearly state what you have tried, how it failed, and what you need help with. Commented Sep 22, 2017 at 13:00

1 Answer 1

2

DynamoDB is a NoSQL database. This is the default feature in most of the NoSQL databases. This is supported in DynamoDB as well. Like RDBMS, the NoSQL database doesn't have any schema. You can add any non-key attributes anytime.

With respect to DynamoDB, while creating the table, it doesn't allow to define any non-key attributes. The lastName is a non-key attribute. It can be added to the item (i.e. record) at any time after you create the item (or) while creating the new item. This is one of the main advantages of NoSQL or DynamoDB database.

UpdateExpression = 'SET lastName = :lastNameVal',   
ExpressionAttributeValues={':lastNameVal' : 'John'}

Reference link

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.