aletrn commited on
Commit
c6054f0
·
1 Parent(s): 243f395

[feat] switch to aws lambda powertools logger

Browse files
dockerfiles/dockerfile-base-webserver CHANGED
@@ -15,10 +15,11 @@ COPY ./scripts/lambda-entrypoint.sh /lambda-entrypoint.sh
15
  RUN chmod +x /lambda-entrypoint.sh
16
  RUN ls -l /lambda-entrypoint.sh
17
 
 
18
  COPY ./src ${LAMBDA_TASK_ROOT}/src
19
 
20
  RUN apt update && apt install -y python3-pip
21
- RUN python -m pip install awslambdaric
22
 
23
  ENTRYPOINT ["/lambda-entrypoint.sh"]
24
  CMD [ "src.app.lambda_handler" ]
 
15
  RUN chmod +x /lambda-entrypoint.sh
16
  RUN ls -l /lambda-entrypoint.sh
17
 
18
+ COPY requirements_dev.txt ${LAMBDA_TASK_ROOT}/requirements_dev.txt
19
  COPY ./src ${LAMBDA_TASK_ROOT}/src
20
 
21
  RUN apt update && apt install -y python3-pip
22
+ RUN python -m pip install -r requirements_dev.txt
23
 
24
  ENTRYPOINT ["/lambda-entrypoint.sh"]
25
  CMD [ "src.app.lambda_handler" ]
requirements.txt CHANGED
@@ -1,3 +1,4 @@
 
1
  bson
2
  python-dotenv
3
  segment-geospatial
 
1
+ aws-lambda-powertools
2
  bson
3
  python-dotenv
4
  segment-geospatial
requirements_dev.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ awslambdaric
2
+ aws_lambda_powertools
3
+ jmespath
4
+
src/app.py CHANGED
@@ -1,8 +1,22 @@
1
  import json
2
- import logging
3
 
 
 
4
 
5
- def lambda_handler(event, context):
6
- logging.debug(f"event:{event}...")
7
- logging.debug(f"context:{context}...")
8
- return {"msg": f"ciao{json.dumps(event)}."}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import json
 
2
 
3
+ from aws_lambda_powertools import Logger
4
+ from aws_lambda_powertools.utilities.typing import LambdaContext
5
 
6
+ logger = Logger()
7
+
8
+
9
+ # @logger.inject_lambda_context
10
+ def lambda_handler(event: dict, context: LambdaContext) -> dict[str]:
11
+ try:
12
+ logger.info("start")
13
+ logger.debug("debug...")
14
+ logger.info(f"event:{json.dumps(event)}...")
15
+ logger.info(f"context:{context}...")
16
+ logger.info("end")
17
+ if event["test"] > 100:
18
+ raise ValueError(f"value test {event['test']} too high!")
19
+ return {"test": event["test"]}
20
+ except Exception as e:
21
+ logger.error(f"exception:{e}.")
22
+ return {"msg": "internal server error"}