- I have dynamodb table
- I need to remove 2 keys(type, code) from all the items, and update another key into each item(msg)
- id is the partitionkey
- How to delete the attribute
typefrom each item if my type is only Fail? - There is no condition for
codeit should be deleted from each item
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('test-table')
result = table.scan()
scan_response = result.copy()
while 'LastEvaluatedKey' in result:
result = table.scan(ExclusiveStartKey=result['LastEvaluatedKey'])
scan_response['Items'].extend(result['Items'])
for each in scan_response['Items']:
table.update_item(
Key={
'id': each['id']
},
AttributeUpdates={
'msg': {
'Value': ''
},
}
)
table.update_item(
Key={
'id': each['id']
},
UpdateExpression='REMOVE type, code'
)
Above code is working fine, I am able to delete type and code and update msg from every item
Documentation saying i cant do the operation at one shot(UpdateExpression, AttributeUpdates)