| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import boto3
- # use Resource
- def increase_rating(keya,dynamodb=None):
- if not dynamodb:
- dynamodb = boto3.resource('dynamodb')
- table = dynamodb.Table('hehe')
-
- response = table.update_item(
- Key={'name': keya},
- UpdateExpression="set alias=:val",
- ExpressionAttributeValues={
- ':val': 'hehe'},
- ReturnValues="UPDATED_NEW")
- return response
- # use Client
- def updata_ddb(name,msg,alias):
- table = boto3.client('dynamodb')
- table.update_item(TableName='hehe',
- Key={'name': {'S':name}},
- UpdateExpression='SET name = :name, alias = :alias',
- ExpressionAttributeValues={
- ':name': {
- 'S': msg},
- ':alias':{
- 'S': alias}
- })
- def updata_ddbone(age):
- client = boto3.client('dynamodb')
- response = client.update_item(
- TableName='age',
- Key={
- 'key': {
- 'S': "name"
- }
- },
- AttributeUpdates={
- 'age': {
- 'Value': {
- 'S': age
- }
- }
- }
- )
-
- if __name__ == '__main__':
- update_response = increase_rating("cxy")
- print("Update movie succeeded:")
|