-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_dynamodb.py
44 lines (37 loc) · 880 Bytes
/
aws_dynamodb.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
38
39
40
41
42
43
44
import boto3 # sdk
client = boto3.client('dynamodb',
# keys for user with IAM permissions on dynamodb
aws_access_key_id='iam_key',
aws_secret_access_key='iam_secret_key',
region_name='selected_region')
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')
print(table.item_count)
# GetItem
response = table.get_item(
Key={'id': '1'}
)
print(response['Item'])
# Scan (get all)
response = table.scan()
print(response['Items'])
# PutItem
table.put_item(
Item={
'id': '3',
'firstname': 'Paul',
'lastname': 'Kerry'
}
)
# UpdateItem
table.update_item(
Key={'id': '3'},
UpdateExpression='SET firstname = :newfn',
ExpressionAttributeValues={
':newfn': 'Alex'
}
)
# DeleteItem
table.delete_item(
Key={'id': '3'}
)