-
Notifications
You must be signed in to change notification settings - Fork 429
Access defined runtime environment variables from powertools #1172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@heitorlessa :) I would like this by like this: https://www.starlette.io/config/ |
@Fahadmo personally speaking, I think this idea is brilliant. Thanks for sharing it with us. AppConfig is outside the scope of this issue, but curious to hear about how do you see this functionality working together with AppConfig (another configuration source for Lambda)? |
@heitorlessa - So far i have found a couple interesting libraries as an inspiration for a simple framework for environment variables, defaults (.env or json settings) and parameters (appconfig, ssm, secrets manager etc..):
Personally i kind of likely the simpler config = Configuration(loaders=[Environment(), EnvFile(filename=env_file), ParameterStore(), ...])
DEBUG = config('DEBUG', cast=bool, default=False)
DATABASE_URL = config('DATABASE_URL', cast=databases.DatabaseURL)
SECRET_KEY = config('SECRET_KEY', cast=Secret)
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=CommaSeparatedStrings)
|
For people who use the parser and pydantic, there's already a very simple solution. Pydantic also has support for secrets and loading configuration from files. Just a thought ;) |
Simple but I want a zero dependency version. |
So you dont want to add prettyconf or Starlette ? just implement a leaner version? |
no. just the UX. |
"couple interesting libraries as an inspiration for a simple framework" |
I respect that. |
i don't see the need for 70mb dependency i don't want for a simple environment utility which can be performs using vanilla python 3.7+. When a lambda is >5mb in size the performance drops too much for me use case. Hopefully v2 of powertools is closer on the roadmap to allow for even smaller lambdas. |
From my experience, the init time for my lambdas is in the regular time, no performance issues (and i monitor them). And about pydantic - I use it in so many other use cases that's it's as integral as powertools. But to each his own. |
i just don't want to use pydantic :( |
and that's just fine :) |
|
@heitorlessa - would it be possible to expand on what |
You can see a full implementation (with tests and full documentation) in my best practices github project. The schema for the env vars: https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/service/handlers/schemas/env_vars.py and a blog explaining why this is important ;) @heitorlessa FYI in case you want it for the extras package |
@ran-isenberg zero dependencies? Coz I thought this would be part of core library, to reduce the use of static constants and cut down on the boilerplate. As Powertools uses environment variables for a lot of things, log level, feature toggles or overriding service names. It should just be very something and lightweight
If can of coz be extended to do extra stuff in your BYO implementations. Or just to append your own set of environment variables. |
No, like I said, it uses Pydantic for parsing, so it can only used in the extras. For those who already use pydantic, this is a no brainer. |
Yep. Definitely a plus for the Pydantic specific lambdas and possible an entire theme on its own. Currently it looks like the project will be on lock down until the end of July. So hopefully after that there is some directions on
|
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
related: #1172 We're following closely Pydantic v2 (~17x faster and much smaller package) which could address this in a better way as defined in #1172. |
Hello everybody! To add this feature, we need to support Pydantic and validate environment variables against a Pydantic model. We need to serialize different types like string, int, classes and others. To optimize Lambda execution, we need to cache models and values to avoid running Pydantic operations every time, and other things. The things mentioned above make creating this utility complex and at this moment we are focusing on other things like OpenAPI specifications, external observability provider, new backend for Idempotency and others. Alternatively, we suggest using the AWS Lambda Environment Variables Modeler (Python) project. @ran-isenberg is one of the Powertools for AWS Lambda (Python) contributors and created this project. I'm sure Ran will be happy to address feedback, implement new features, and fix bugs if they exist. AWS Lambda Environment Variable Modeler (Python) Features:
Thank you and I'm closing this issue. |
|
Is your feature request related to a problem? Please describe.
AWS Lambda has defined runtime environment variables as shown here: https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
In order to get the name of the variable we often need to go back to the documentation which can be frustrating.
Describe the solution you'd like
I would like to have something that would let me access all defined environment variables.
For example, this could be a class with a list of cached properties for each defined runtime variable.
Describe alternatives you've considered
Currently, we just run the following for each environment variable we need.
The text was updated successfully, but these errors were encountered: