feat(parameters): add support for AppConfig Agent#5399
Conversation
5d0bfe0 to
ba6478b
Compare
…rtools/powertools-lambda-typescript into feat/parameters-appconfig-agent
| } | ||
| ); | ||
| value = await res.text(); | ||
| if (res.status === 404) { |
There was a problem hiding this comment.
Note: we always throw if a parameter is not found. If we want to do something different and say return undefined, then we need to revisit the behaviour when we are not running in a lambda because currently that is what undefined means.
The issue here is I can't think of a different way to represent not running in a lambda other than throwing: we can't do what we do in metdata by just returning an empty object because that is a valid return value for a parameter.
Open to suggestions here: maybe allowing users to supply a default value that means they can avoid this ParameterNotFoundError error. There is also the issue that we are missing the throwOnMissing behaviour that other parameter types have, which could confuse users.
There was a problem hiding this comment.
This for me is the biggest one-way door / question mark to be honest.
On one hand, I understand why we're throwing based on your explanation above, but on the other hand I don't think it's in line with the rest of the library and that's a minus - which you also have pointed out.
What do you think about not throwing unless throwOnMissing is present and also returning a clearly fake object like:
{
"testing": true
}or something like this - which would have to properly document.
Conversely, what would it take for us to allow customers to specify what to return? Would having something like POWERTOOLS_APPCONFIG_AGENT_RETURN_VALUE="{\"foo\": true}" be an option?
There was a problem hiding this comment.
Went with a combination of both of your suggestions, implemented in 113fc08:
- 404 now returns
undefinedby default, in line with the rest of the library (DynamoDB/AppConfig provider semantics). This also means users get per-call fallback values for free via nullish coalescing —await getConfig(...) ?? DEFAULT_FLAGS— which we think covers the 'return a specific value when not found' use case with full type safety and no new API. throwOnMissing: trueopts intoParameterNotFoundError, same flag and semantics as the provider-based functions, including theGetMaybeUndefinedreturn-type narrowing.POWERTOOLS_APPCONFIG_AGENT_RETURN_VALUEfor the not-in-Lambda case: rather than a hardcoded fake object (which would be a type lie for the no-transform/binarycases and a dangerously plausible{}forjson), the env var value is treated as the agent response body and runs through the normal transform pipeline. Users pick a shape-correct value for their config; unset meansundefinedas before. Documented in a new 'Testing getConfig' section with a snippet.
On the fake-object idea specifically: anything the library invents can't satisfy the string return branches, and for json an empty-ish object reads as 'all flags off' with no failure signal — the env var sidesteps both since the customer supplies the value.
…rtools/powertools-lambda-typescript into feat/parameters-appconfig-agent
|



Summary
Adds a new
getConfigfunction exported from@aws-lambda-powertools/parameters/appconfig-agentthat retrieves configurations from the AWS AppConfig Agent Lambda extension's local HTTP endpoint. Since caching, polling, and prefetching are handled by the agent, the implementation is a lean standalone function modeled on the commonsmetadatamodule rather than theBaseProviderpattern, keeping customer bundles small.Changes
getConfigfunction inpackages/parameters/src/appconfig-agent/that fetches fromhttp://localhost:2772/applications/{app}/environments/{env}/configurations/{config}using nativefetchwith a configurable timeout (default 3000ms)jsonandbinarytransforms by reusing the existingtransformValueutility; nomaxAge/forceFetchoptions since caching is handled by the agentundefinedwhen not running in a Lambda environment (local development/testing)AWS_APPCONFIG_EXTENSION_HTTP_PORTenvironment variable and fall back toPOWERTOOLS_SERVICE_NAMEwhenapplicationis not provided./appconfig-agentand./appconfig-agent/typessubpath exports with typed return values (string,JSONValue, or explicit generic)Issue number: closes #5312
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.