-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamo.py
36 lines (29 loc) · 894 Bytes
/
dynamo.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
import boto3
# Use the DynamoDB resource object
dynamodb = boto3.resource('dynamodb')
# Reference the table
table_name = "lotteryentriesdb"
table = dynamodb.Table(table_name)
def delete_db_item(partition_key_value):
response = table.delete_item(
Key={
'name': partition_key_value
}
)
return "Item successfully deleted"
def add_db_item(partition_key_value):
response = table.put_item(
Item={
'name': partition_key_value
}
)
return "Item successfully added"
def get_all_items():
# Perform the initial scan
response = table.scan()
data = response['Items'] # Extract items
# Handle pagination if LastEvaluatedKey exists
while 'LastEvaluatedKey' in response:
response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
data.extend(response['Items'])
return data