UpdateItem.py 592 B

1234567891011121314151617181920
  1. #!/usr/bin/env python
  2. import boto3
  3. import json
  4. import random
  5. TABLE_NAME = 'elaborate_employee_table'
  6. id_numbers = [10, 20, 30, 40, 50, 60, 70, 90, 100]
  7. client = boto3.client('dynamodb')
  8. for id_number in id_numbers:
  9. response = client.update_item(
  10. TableName=TABLE_NAME,
  11. Key={'id': {'N': '{}'.format(id_number)}},
  12. UpdateExpression='SET #ct = :ctv',
  13. ExpressionAttributeValues={':ctv': {'S':'permanent'}},
  14. ExpressionAttributeNames={'#ct': 'contract_type'},
  15. ReturnValues='UPDATED_OLD')
  16. print(json.dumps(response['Attributes'], indent=4))