12/08/2021

increase number in dynamodb field key value

 

Get Access permission

.

import boto3
##########################################################
ACCESS_KEY = 'xxxx'
SECRET_KEY = 'xxx'
dynamo_client = boto3.client('dynamodb',
aws_access_key_id = ACCESS_KEY,
aws_secret_access_key = SECRET_KEY
)

.


sample code

.

#update when db
def update_when_db(who, when):
dynamo_client.update_item(
TableName='president_when', #table name
Key={'when': {'S': when}}, #primary key filed name, #key value, if key file not exist, it will create
UpdateExpression="ADD #counter :increment",
ExpressionAttributeNames={'#counter': who}, #key filed name that you want to increase
ExpressionAttributeValues={':increment': {'N': '1'}} #increase 1
)

.


Thank you.

πŸ™‡πŸ»‍♂️


www.marearts.com




No comments:

Post a Comment