Last active
June 13, 2023 23:43
-
-
Save nquayson/e35eceb97db7432915cc97a2f89f3dd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import boto3 | |
client = boto3.client('dynamodb') | |
table = os.environ["TABLE_NAME"] | |
def update_hit(): | |
response = client.update_item( | |
TableName=table, | |
Key={'id': {'S': "1"}}, | |
ReturnValues='UPDATED_NEW', | |
UpdateExpression='ADD hit_count :val', | |
ExpressionAttributeValues={":val": {"N": "1"}} | |
) | |
return response["Attributes"]["hit_count"]["N"] | |
def handler(event, context): | |
item = update_hit().zfill(5) | |
result = { | |
"statusCode": 200, | |
"statusDescription": "200 OK", | |
"isBase64Encoded": False, | |
"headers": {"Content-Type": "text/json; charset=utf-8"}, | |
"body": item | |
} | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment