Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
sample-helper-aws-appconfig
Advanced tools
A sample helper Python library for AWS AppConfig which makes rolling configuration updates out easier.
bytes
type.pip install sample-helper-aws-appconfig
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
}
Please see the AWS AppConfig documentation for details on configuring the service.
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.
The configuration is not automatically fetched unless you set fetch_on_init
. To have the library fetch the configuration when it is accessed, if it has been more than max_config_age
seconds since the last fetch, set fetch_on_read
.
If you need to customise the AWS credentials or region, set session
to a configured boto3.Session
object. Otherwise, the standard boto3 logic for credential/configuration discovery is used.
The configuration from AWS AppConfig is available as the config
property. Before accessing it, you should call update_config()
, unless you specified fetch_on_init or fetch_on_read during initialisation. If you want to force a config fetch, even if the number of seconds specified have not yet passed, call update_config(True)
.
update_config()
returns True
if a new version of the configuration was received. If no attempt was made to fetch it, or the configuration received was the same as current one, it returns False
. It will raise ValueError
if the received configuration data could not be processed (e.g. invalid JSON). If needed, the inner exception for JSON or YAML parsing is available as __context__
on the raised exception.
To read the values in your configuration, access the config
property. For JSON and YAML configurations, this will contain the structure of your data. For plain text configurations, this will be a simple string.
The original data received from AppConfig is available in the raw_config
property. Accessing this property will not trigger an automatic update even if fetch_on_read
is True. The content type field received from AppConfig is available in the content_type
property.
For example, with the following JSON in your AppConfig configuration profile:
{
"hello": "world",
"data": {
"is_sample": true
}
}
you would see the following when using the library:
# appconfig is the instance of the library
>>> appconfig.config["hello"]
"world"
>>> appconfig.config["data"]
{'is_sample': True}
AWS AppConfig is best used in Lambda by taking advantage of Lambda Extensions
See CONTRIBUTING for more information.
This library is licensed under Apache-2.0. See the LICENSE file.
FAQs
Sample helper library for AWS AppConfig
We found that sample-helper-aws-appconfig demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.