changed Lambda demo to support AWS Academy and create individual bucket for group with globally unique name in S3

This commit is contained in:
Sebastian Rieger
2022-06-20 12:48:38 +02:00
parent 7059688b5d
commit 1f4a435d84
4 changed files with 98 additions and 24 deletions

View File

@ -1,11 +1,20 @@
# import json
import base64
import os
import boto3
def lambda_handler(event, context):
print('## ENVIRONMENT VARIABLES')
print(os.environ)
print('## EVENT')
print(event)
globally_unique_s3_group_bucket_name = os.environ.get("bucketName")
print('Trying to access bucket: ' + globally_unique_s3_group_bucket_name)
s3_client = boto3.client('s3')
response = s3_client.get_object(Bucket='cloudcomp-counter', Key='us-east-1')
response = s3_client.get_object(Bucket=globally_unique_s3_group_bucket_name, Key='us-east-1')
counter = int(response['Body'].read().decode('utf-8'))
@ -20,11 +29,11 @@ def lambda_handler(event, context):
if incr is not 0:
counter = counter + incr
response = s3_client.put_object(Bucket='cloudcomp-counter', Key='us-east-1', Body=str(counter))
response = s3_client.put_object(Bucket=globally_unique_s3_group_bucket_name, 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'
output = ('<html><head><title>Counter Demo</title>\n'
# '<meta http-equiv="refresh" content="5"/></head><body>\n'
'<h2>HS Fulda Cloud Computing - Counter Demo</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'