-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamo-Actions.py
37 lines (33 loc) · 1.08 KB
/
Dynamo-Actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import boto3
from botocore.exceptions import ClientError
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('MyTable')
def put_item(key, value):
"""
Put an item into our table.
"""
try:
response = table.put_item( Item={ 'my-key': key, 'some-other-key': value )
print(f"Successfully added new item")
print(f"Response : {response}")
except ClientError as ce:
print(f"Failed to creat new item - key : {key}, value : {value}")
print(ce)
def update_nested_item(key, value):
"""
Update a nested item. create
"""
try:
response = table.update_item( Key={ 'my-key': key },
UpdateExpression='SET #other-key = :new_value',
ExpressionAttributeNames={
'#other-key': 'New-Key'
},
ExpressionAttributeValues={ ':new_value': True },
ReturnValues='ALL_NEW'
)
print("Successfully created/updated item.")
print(f"Response : {response}")
except ClientError as ce:
print(f"Failed to update item : {ce}")