Browse Source

update py/DynamoDB-UpdateItem.py.

xdc 5 years ago
parent
commit
7cf4642709
1 changed files with 17 additions and 2 deletions
  1. 17 2
      py/DynamoDB-UpdateItem.py

+ 17 - 2
py/DynamoDB-UpdateItem.py

@@ -1,6 +1,7 @@
 import boto3
 
-    
+
+# use Resource    
 def increase_rating(keya,dynamodb=None):
     if not dynamodb:
         dynamodb = boto3.resource('dynamodb')
@@ -14,7 +15,21 @@ def increase_rating(keya,dynamodb=None):
             ':val': 'hehe'},
         ReturnValues="UPDATED_NEW")
     return response
-   
+
+# use Client        
+def updata_ddb(name,msg,alias):
+    client = boto3.client('dynamodb')
+    table.update_item(TableName='hehe',
+        Key={'mykey': {'S':name}},
+        UpdateExpression='SET name = :name, alias = :alias',
+        ExpressionAttributeValues={
+        ':name': {
+            'S': msg},
+        ':alias':{
+            'S': alias}
+            })
+
+
  
 if __name__ == '__main__':
     update_response = increase_rating("cxy")