-
Notifications
You must be signed in to change notification settings - Fork 421
/
Copy pathbuiltin_provider_ssm_with_no_recursive.py
37 lines (27 loc) · 1.34 KB
/
builtin_provider_ssm_with_no_recursive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from typing import Any
import requests
from aws_lambda_powertools.utilities import parameters
from aws_lambda_powertools.utilities.typing import LambdaContext
ssm_provider = parameters.SSMProvider()
class ConfigNotFound(Exception): ...
def lambda_handler(event: dict, context: LambdaContext):
try:
# Retrieve multiple parameters from a path prefix
# /config = root
# /config/endpoint = url
# /config/endpoint/query = querystring
all_parameters: Any = ssm_provider.get_multiple("/config", recursive=False)
endpoint_comments = "https://jsonplaceholder.typicode.com/comments/"
for parameter, value in all_parameters.items():
# query parameter is used to query endpoint
if "query" in parameter:
endpoint_comments = f"{endpoint_comments}{value}"
break
else:
# scheme config was not found because get_multiple is not recursive
raise ConfigNotFound("URL query parameter was not found")
# the value of parameter is https://jsonplaceholder.typicode.com/comments/
comments: requests.Response = requests.get(endpoint_comments)
return {"comments": comments.json()}
except parameters.exceptions.GetParameterError as error:
return {"comments": None, "message": str(error), "statusCode": 400}