Skip to content

AWSSource

A ConfigSource that loads values recursively from an AWS SSM path.

Warning

In order to use this source you must have boto3 installed either directly or by including the "aws" extra when installing this package (e.g. poetry install flex-config -E aws).

Parameters:

Name Type Description Default
path str

a prefix in AWS SSM to read from.

required

Info

You can pass any keyword arguments to this class that you would to boto3 directly (e.g. secret key).

items(self)

Returns a generator for getting all path, value pairs

Source code in flex_config\aws_source.py
62
63
64
def items(self) -> Iterable[Tuple[str, Any]]:
    """ Returns a generator for getting all path, value pairs """
    return self.to_dict().items()

to_dict(self)

Returns a generator for getting all path, value pairs

Source code in flex_config\aws_source.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def to_dict(self) -> Dict[str, Any]:
    """ Returns a generator for getting all path, value pairs """
    kwargs: Dict[str, Any] = {}
    param_dict: Dict[str, Any] = {}
    while True:
        result = self.ssm.get_parameters_by_path(
            Path=f"/{self.path}/", Recursive=True, WithDecryption=True, **kwargs
        )

        for param in result["Parameters"]:
            path = param["Name"].replace(f"/{self.path}/", "")  # Don't repeat SSM path in key
            param_dict = insert_value_at_nested_key(
                dest_dict=param_dict, subkey_path=path.split("/"), value=param["Value"]
            )

        kwargs["NextToken"] = result.get("NextToken")
        if kwargs["NextToken"] is None:  # That's the last of the values
            break
    return param_dict