You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

42 lines
1.4 KiB

# import json
import base64
import boto3
def lambda_handler(event, context):
s3_client = boto3.client('s3')
response = s3_client.get_object(Bucket='cloudcomp-counter', Key='us-east-1')
counter = int(response['Body'].read().decode('utf-8'))
debug = ""
incr = 0
if 'body' in event:
body = str(base64.b64decode(event['body']).decode("utf-8"))
if body.startswith('input'):
incr = int(body.rsplit('=')[1])
elif 'input' in event:
incr = int(event['input'])
if incr is not 0:
counter = counter + incr
response = s3_client.put_object(Bucket='cloudcomp-counter', Key='us-east-1', Body=str(counter))
output = ('<html><head><title>TCPTimeCounter REST Service</title>\n'
'<meta http-equiv="refresh" content="5"/></head><body>\n'
'<h2>HS Fulda - TCPTimeCounter REST Service</h2>\n'
'<p><b>HTML-Output:</b> ' + str(counter) + '</p></body>\n'
'<form method=POST action="">\n'
'<input type="hidden" name="input" value="1">\n'
'<input type="submit" value="Increment"></form>\n'
# '<hr><b>Lambda Event:</b><br>' + repr(event) + '\n'
# '<hr><b>Lambda Context:</b><br>' + repr(context) + '\n'
'</body></html>\n')
return {
'statusCode': 200,
'headers': {
'Content-Type': 'text/html',
},
'body': output
}