Skip to content

AppConfig Extension

AWS AppConfig configuration retrieval through the AWS AppConfig Agent Lambda extension

CLASS DESCRIPTION
AppConfigExtensionProvider

AWS AppConfig provider backed by the AWS AppConfig Agent Lambda extension.

AppConfigExtensionProvider

AppConfigExtensionProvider(environment: str, application: str | None = None, port: int | None = None, timeout: float = DEFAULT_EXTENSION_TIMEOUT_SECS)

Bases: BaseProvider

AWS AppConfig provider backed by the AWS AppConfig Agent Lambda extension.

The extension runs as a Lambda layer, keeps a local cache of configuration data, polls AWS AppConfig in the background, and serves configuration over HTTP on localhost. This provider reads from that local endpoint instead of calling the AppConfig APIs with boto3.

PARAMETER DESCRIPTION
environment

Environment of the configuration

TYPE: str

application

Application of the configuration, by default POWERTOOLS_SERVICE_NAME

TYPE: str | None DEFAULT: None

port

Port of the extension's local HTTP server, by default AWS_APPCONFIG_EXTENSION_HTTP_PORT or 2772

TYPE: int | None DEFAULT: None

timeout

Seconds to wait for a response from the extension, by default 3

TYPE: float DEFAULT: DEFAULT_EXTENSION_TIMEOUT_SECS

Example

Retrieves a configuration from the AppConfig Agent Lambda extension

1
2
3
4
5
>>> from aws_lambda_powertools.utilities import parameters
>>>
>>> appconf_provider = parameters.AppConfigExtensionProvider(environment="my_env", application="my_app")
>>>
>>> value: dict = appconf_provider.get("my_conf", transform="json")

Retrieves selected feature flags only

1
>>> value: dict = appconf_provider.get("my_flags", transform="json", flag=["beta_ui", "new_checkout"])
Notes

Attach the AWS-AppConfig-Extension layer to the function and grant the execution role appconfig:StartConfigurationSession and appconfig:GetLatestConfiguration. The extension uses those permissions; this provider only talks to localhost.

Source code in aws_lambda_powertools/utilities/parameters/appconfig_extension.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def __init__(
    self,
    environment: str,
    application: str | None = None,
    port: int | None = None,
    timeout: float = DEFAULT_EXTENSION_TIMEOUT_SECS,
):
    super().__init__()
    self.environment = environment
    self.application = resolve_env_var_choice(
        choice=application,
        env=os.getenv(constants.SERVICE_NAME_ENV, "service_undefined"),
    )
    self.port = (
        port if port is not None else int(os.getenv(constants.APPCONFIG_EXTENSION_PORT_ENV, DEFAULT_EXTENSION_PORT))
    )
    self.timeout = timeout