-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_item.py
40 lines (33 loc) · 1.24 KB
/
update_item.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
"""
AWS_DynamoDB_Solutions #kiddjsh
"""
"""
Updates items to an Amazon DynamoDB table used to store data.
The table uses Entity as the partition key, no sort key is used.
:Python Version: Python 3.7.10
:param Key: The primary key of the item to be updated.
:param UpdateExpression: A collection of attributes containing at least name.
"""
# boto3 is the aws software development kit (sdk) for python
import boto3
# Gets the service resource.
DDB_RESOURCE = boto3.resource("dynamodb", region_name="us-east-1")
# A resource representing an Amazon DynamoDB Table
table = DDB_RESOURCE.Table("Architecture")
# The primary key of the item to be updated and a value for that attribute.
Entity = "00011"
# Edits an item's attribute, or adds a new item if it does not already exist.
table.update_item(
#The primary key of the item to be updated.
Key={
"Entity": Entity
},
#An expression that defines one or more attributes to be updated.
UpdateExpression="SET Echo = :E",
#One or more values that can be substituted in an expression.
ExpressionAttributeValues={
":E": "AWS Cloud Architect"
},
#Returns only the updated attributes, after the UpdateItem operation.
ReturnValues="UPDATED_NEW"
)