Sample helper library for AWS AppConfig
Maintained. Last release 6 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install sample-helper-aws-appconfigSample AWS AppConfig Helper
A sample helper Python library for AWS AppConfig which makes rolling configuration updates out easier.
Features
- Configurable update interval: you can ask the library to update your configuration as often as needed, but it will only call the AWS AppConfig API at the configured interval (in seconds).
- Handles correct API usage: the library uses the new AppConfig Data API and handles tracking the next configuration token and poll interval for you.
- Flexible: Can automatically fetch the current configuration on initialisation, every time the configuration is read by your code, or on demand. You can override the caching interval if needed.
- Handles YAML, JSON and plain text configurations, stored in any supported AppConfig store. Any other content type is returned unprocessed as the Python
bytestype. - Supports AWS Lambda, Amazon EC2 instances and on-premises use.
Installation
pip install sample-helper-aws-appconfig
Example
from appconfig_helper import AppConfigHelper
from fastapi import FastAPI
appconfig = AppConfigHelper(
"MyAppConfigApp",
"MyAppConfigEnvironment",
"MyAppConfigProfile",
45 # minimum interval between update checks
)
app = FastAPI()
@app.get("/some-url")
def index():
if appconfig.update_config():
print("New configuration received")
# your configuration is available in the "config" attribute
return {
"config_info": appconfig.config
}
Usage
Please see the AWS AppConfig documentation for details on configuring the service.
Initialising
Start by creating an AppConfigHelper object. You must specify the application name, environment name, and profile (configuration) name. You must also specify the refresh interval, in seconds. AppConfigHelper will not attempt to fetch a new configuration version from the AWS AppConfig service more frequently than this interval. You should set it low enough that your code will receive new configuration promptly, but not so low that it takes too long. The library enforces a minimum interval of 15 seconds.