AWS Lambda
Last updated
Was this helpful?
Was this helpful?
def lambda_handler(event, context):
# This is an example.
# Make sure you store the sharedSecret in a safe place,
# e.g. using AWS Secret Manager.
sharedSecret='[Fill in your shared secret]'
requestBody=event['body']
thingsMessageToken=event['headers']['things-message-token']
input = requestBody + sharedSecret;
def calculate_sha256(data):
# Convert data to bytes if it’s not already
if isinstance(data, str):
data = data.encode()
# Calculate SHA-256 hash
sha256_hash = hashlib.sha256(data).hexdigest()
return sha256_hash
if thingsMessageToken == calculate_sha256(input):
# Define further action
return {
'statusCode': 201,
}
else:
return {
'statusCode': 401,
}