This is two part question for first part Updating the value of DynamoDB table with boto3 implemented lambda function
now what i am trying to achieve is having dynamic value to update
def lambda_handler(event, context):
param = event['queryStringParameters']['employeID']
name = event['queryStringParameters']['employeName']
dynamodb = boto3.resource('dynamodb', region_name="us-east-1")
table = dynamodb.Table('api_demo_employe')
column = [cloumn1,cloumn2......]
for i in range(0,len(column):
query = 'SET {} = :f'.format(column[i])
response = table.update_item(
Key = {
'employeID' : param
},
ExpressionAttributeValues = {
':f': name
},
UpdateExpression = query
)
I am getting an error
"errorMessage": "An error occurred (ValidationException) when calling the UpdateItem operation: One or more parameter values were invalid: Cannot update attribute employeID. This attribute is part of the key",
I know the issue is with how i am handling UpdateExpression
Could any one help me put with this one?
You’re trying to update the item’s key, which doesn’t work. You will have to delete and recreate the item.
For details, please refer to the Amazon DynamoDB documentation:
You cannot use
UpdateItem
to update any primary key attributes. Instead, you will need to delete the item, and then usePutItem
to create a new item with new attributes.