From 2c2878be7d965e6e0b4e7f3c07ffb9106a66009a Mon Sep 17 00:00:00 2001 From: Niccolo' Zanotti Date: Wed, 4 Sep 2024 02:11:21 +0200 Subject: [PATCH] Rename lambda function to adhere with structure required by AWS lambda. --- .github/workflows/deploy-lambda-to-aws.yml | 2 +- registration-app.py => lambda_function.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) rename registration-app.py => lambda_function.py (92%) diff --git a/.github/workflows/deploy-lambda-to-aws.yml b/.github/workflows/deploy-lambda-to-aws.yml index 986e5d1..94faf9b 100644 --- a/.github/workflows/deploy-lambda-to-aws.yml +++ b/.github/workflows/deploy-lambda-to-aws.yml @@ -28,7 +28,7 @@ jobs: cd package zip -r9 ../lambda_function.zip . cd .. - zip -g lambda_function.zip registration-app.py + zip -g lambda_function.zip lambda-function.py - name: Deploy to AWS Lambda env: diff --git a/registration-app.py b/lambda_function.py similarity index 92% rename from registration-app.py rename to lambda_function.py index 74be1ec..dd4f7b9 100644 --- a/registration-app.py +++ b/lambda_function.py @@ -3,7 +3,7 @@ from datetime import datetime, timezone import csv import boto3 -import os + app = Flask(__name__) CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True) @@ -26,16 +26,16 @@ def register(): name = data['name'] occupants.add(name) log_action(name, 'register') - return jsonify({"status": "registered", "occupants": len(occupants)}) + return jsonify({"status": "registered", "occupants": list(occupants)}) @app.route('/unregister', methods=['POST']) def unregister(): data = request.json name = data['name'] - occupants.remove(name) + occupants.discard(name) # set.discard() avoids KeyError if name not in set log_action(name, 'unregister') - return jsonify({"status": "unregistered", "occupants": len(occupants)}) + return jsonify({"status": "unregistered", "occupants": list(occupants)}) @app.route('/status', methods=['GET'])