--Touch DynamoDB from MAC --Table operations with pynamoDB
--AWS Access Key ID and AWS Secret Access Key have been GET
Let's go!
(venv) mbp:wanted user$ aws configure
AWS Access Key ID [None]: ABCDEFGHIJGLMNOPQRSTUVWXYZ
AWS Secret Access Key [None]: SECRETKEYSECRETKEYSECRETKEYSECRETKEY
Default region name [None]: ap-northeast-1
Default output format [None]:
Interactively, enter the access key and secret key to complete the cooperation
from datetime import datetime
from pynamodb.attributes import UnicodeAttribute, UTCDateTimeAttribute, MapAttribute, NumberAttribute
from pynamodb.models import Model
class AccountMap(MapAttribute):
"""
account information
"""
price = NumberAttribute(null=True)
search_limit_num = NumberAttribute(null=True)
url = UnicodeAttribute(null=True)
class Users(Model):
"""
User information
"""
class Meta:
table_name = "Users"
region = 'ap-northeast-1'
id = UnicodeAttribute(hash_key=True)
password = UnicodeAttribute()
login_date = UTCDateTimeAttribute()
start_date = UTCDateTimeAttribute(default=datetime.now())
account = AccountMap()
#Creating a user table
if not Users.exists():
Users.create_table(read_capacity_units=1, write_capacity_units=1, wait=True)
You can make it like this. Django feeling, odd ^ ^
query Specify the key and then search
def get_user_info(user_id, password, month_password):
"""
Password authentication
:param user_id:
:param password:
:param month_password:
:return:
"""
#Get TODO token
token = "local"
#User ID and password and this month's password and token
for user_data in Users.query(user_id, (Users.password == password) & (Users.month_password == month_password) & (
Users.token == token)):
return user_data
return None
Search with query
scan Search without specifying a key
Users.scan(Users.id==user_id)
#Data creation
users = Users('onehundred')
users.password = "password"
users.token = "local"
users.month_password = "month_password"
users.login_date = datetime.now()
users.start_date = datetime.now()
users.account = {
"price": 1000,
"search_limit_num": 10,
"pay_pal_url": "https://paypal.com",
}
users.save()
Recommended Posts