Dynamo Dictionary
Easily Use DynamoDB as a key-value format.
📝 Table of Contents
🧐 About
Easily Use DynamoDB as a key-value format. You can use following functions.
🏁 Getting Started
Installing
pip install dynamo_dictionary
Prerequisites
1. Access Key required for DynamoDB Authentication. If you don't have Access Key, Please follow below steps.
-
Click below URL.
-
Click
Add user
button. -
Input
User name
and enableProgrammatic access
. -
Click
Attach existing policies directly
and SearchS3FullAccess
and checkAmazonS3FullAccess
and clickNext:Tags
. -
Click
Next:Review
-
copy
Access Key ID
andSecret access Key
to user notepad. -
complete!
3. You need to know which region your dynamodb table is in. If you don't know yet, Please refer to URL below.
https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
3. (Required) Create Handler
Use this code to create handler.
import dynamo_dictionary
table_name = "Your Table Name"
region_name = "Your Region Name"
# You don't need to use these two parameters if your authentication file is in ~/.aws/config.
aws_access_key_id = "YOUR AWS ACCESS KEY ID"
aws_secret_access_key = "YOUR AWS SECRET ACCESS KEY"
handler = dynamo_dictionary.DynamoDictionary(table_name, region_name,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key)
print(handler)
result:
waiting for create table. . .
<dynamo_dictionary.DynamoDictionary object at 0x0136E448>
🎈 Usage
Please check Prerequisites before starting Usage
.
🌱 Put
Use this function to save data into DynamoDB Table.
Examples
>>> print(handler.put("fruit", {"name": "apple", "price": 120}))
{'ResponseMetadata': {'RequestId': 'KS5A9R2ONP5BVK1SK7EH98B89VVV4KQNSO5AEMVJF66Q9ASUAAJG', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'Server', 'date': 'Thu, 06 Aug 2020 17:42:30 GMT', 'content-type': 'application/x-amz-json-1.0', 'content-length': '2', 'connection': 'keep-alive', 'x-amzn-requestid': 'KS5A9R2ONP5BVK1SK7EH98B89VVV4KQNSO5AEMVJF66Q9ASUAAJG', 'x-amz-crc32': '2745614147'}, 'RetryAttempts': 0}}
- If you want check data, check your dynamodb table in DynamoDB Console.
Parameters
-
(required) key
: strfruit
-
(required) value
: dict | list | str | bytes | int | float | ...{"name": "apple", "price": 120}
Returns
- DynamoDB put result :
dict
🌱 Get
Use this function to get data from DynamoDB Table.
Examples
>>> print(handler.get(["fruit"]))
{'fruit': {'name': 'apple', 'price': 120}}
>>> print(handler.get("fruit"))
{'fruit': {'name': 'apple', 'price': 120}}
Parameters
-
(required) keys
: list | str- list of key or key
Returns
- Get result :
dict
🌱 Get All
Use this function to get all data from DynamoDB Table.
Examples
>>> print(handler.get_all())
{'fruit': {'name': 'apple', 'price': 120}, 'fruit-2': {'name': 'banana', 'price': 121}}
Parameters
Returns
- all data of the table :
dict
🌱 Delete
Use this function to delete data from DynamoDB Table.
Examples
>>> print(handler.delete(["fruit"]))
...
>>> print(handler.delete("fruit"))
...
Parameters
-
(required) keys
: list | str- list of key or key
Returns
- dynamoDB delete result list :
list