# 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 = ('TCPTimeCounter REST Service\n' '\n' '

HS Fulda - TCPTimeCounter REST Service

\n' '

HTML-Output: ' + str(counter) + '

\n' '
\n' '\n' '
\n' # '
Lambda Event:
' + repr(event) + '\n' # '
Lambda Context:
' + repr(context) + '\n' '\n') return { 'statusCode': 200, 'headers': { 'Content-Type': 'text/html', }, 'body': output }