Skip to content

Commit

Permalink
Save version1
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkjin99 committed Apr 17, 2024
1 parent b8c4987 commit 6b165eb
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions s3/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
import pytz


def create_response(status_code: str | int, msg: str) -> dict:
response = {
"isBase64Encoded": False,
"headers": {"Content-Type": "application/json"},
"statusCode": status_code,
"body": msg,
}
return response


def read_json_from_s3(bucket_name: str, file_key: str):
s3 = boto3.client("s3")
response = s3.get_object(Bucket=bucket_name, Key=file_key)
Expand All @@ -20,19 +30,17 @@ def read_json_from_s3(bucket_name: str, file_key: str):


def handler(event=None, context=None):
response = None
response = create_response(200, "")
bucket_name = "ssudobi-cache"
file_key = "cache"
try:
last_cached_time, data = read_json_from_s3(bucket_name, file_key)
response = {
"StatusCode": 200,
"last_cached_time": last_cached_time,
"data": data,
}
response = create_response(
200, json.dumps({"last_cached_time": last_cached_time, "data": data})
)

except Exception as e:
response = {"StatusCode": 500, "error": str(e)}
response = create_response(500, json.dumps({"error": str(e)}))

finally:
return response
Expand Down

0 comments on commit 6b165eb

Please sign in to comment.