Created
June 2, 2023 13:44
-
-
Save atze234/60dbef2991e08aba93b875c73578cf41 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 boto3 | |
import time | |
def message_deduplication(message): | |
alerthash = hashlib.md5(message.encode()) | |
ttl = str(int(time.time()+600)) | |
dynamodbclient = boto3.client('dynamodb') | |
response = dynamodbclient.get_item( | |
Key={ | |
'alerthash': { | |
'S': alerthash.hexdigest(), | |
} | |
}, | |
TableName='deduplicationtab', | |
) | |
try: | |
found = response['Item'] | |
if int(found['ttl']['N']) > int(time.time()) : | |
print("Found message hash in DB") | |
return True | |
except KeyError: | |
pass | |
response = dynamodbclient.put_item( | |
Item={ | |
'alerthash': { | |
'S': alerthash.hexdigest(), | |
}, | |
'ttl': { | |
'N': ttl, | |
} | |
}, | |
TableName='deduplicationtab', | |
) | |
return False | |
def lambda_handler(event, context): | |
#[...] | |
if message_deduplication(message): | |
return | |
#[...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment