forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappconfig_with_cache.py
More file actions
24 lines (18 loc) · 821 Bytes
/
Copy pathappconfig_with_cache.py
File metadata and controls
24 lines (18 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from typing import Any
import requests
from aws_lambda_powertools.utilities import parameters
from aws_lambda_powertools.utilities.typing import LambdaContext
def lambda_handler(event: dict, context: LambdaContext):
try:
# Retrieve a single parameter
endpoint_comments: Any = parameters.get_app_config(
name="config",
environment="dev",
application="comments",
max_age=20,
)
# the value of this parameter is https://jsonplaceholder.typicode.com/comments/
comments: requests.Response = requests.get(endpoint_comments)
return {"comments": comments.json()[:10], "statusCode": 200}
except parameters.exceptions.GetParameterError as error:
return {"comments": None, "message": str(error), "statusCode": 400}