1

I have table already and I want to add a new attribute to that table. I am trying to do that with the update_item functionality of dynamDB.

use case: Bid table holds details on the bid of the product. The user accepts the bid, once the bid is accepted, have to add a few attributes to that record like the user information. Not sure if it is the right way or should I have a new table for this.

pratition key is : Pickup, sort key is : DropOff

A Demo example that I am trying currently currently trying to alter the same table and facing the error.

import json
import boto3

def lambda_handler(event, context):
    
    dynamo_client = boto3.resource('dynamodb')
    users = dynamo_client.Table('LoadsandBids')
 
item = event['body']
print("Fuirst") 
users.update_item(
    Key={
        'Pickup': event['body']['Pickup'],
        'DropOff' : event['body']['DropOff']
                
        },
    UpdateExpression='SET #attr1 = :val1',
    ExpressionAttributeNames={'#attr1': 'new_field'},
    ExpressionAttributeValues={':val1': event['body']['new']},
    ReturnValues='UPDATED_NEW'
)
    
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

getting an error:

"An error occurred (ValidationException) when calling the UpdateItem operation: The provided key element does not match the schema",

Could anyone help me out of this and also suggest it I my approach is good or not?

11
  • 1
    Don't have full answer, but role is reserved keyword. in aws docs they show what to do in such cases. Commented Nov 17, 2020 at 10:48
  • let me try it out Commented Nov 17, 2020 at 10:53
  • 1
    @Andre.IDK solved the issue. the issue was with the case of the latter. Should have been "Dropoff" Commented Nov 17, 2020 at 11:51
  • 1
    Your code worked already for me btw. It was just not indented. Commented Nov 17, 2020 at 11:56
  • 1
    @Andre.IDK thank you for the help. the error was at my end. Commented Nov 17, 2020 at 11:57

0

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.