Package: awstanding
AWStandingEasily load variables from AWS Parameter store into environment variables.Why to use AWStanding?Despite it's built on top of Boto3, it has the following key features that eases the development process:Simpler APIError HandlingPagination handling when needed (Saves you a buch of boilerplate)Dynamic Parameters (variables that listen to updates on AWS)S3 Integration made easy with Download/Upload methodsInstallationpipinstallawstandingI personally recommend using pipenv:pipenvinstallawstandingQuickstartfromawstanding.parameter_storeimportload_parametersload_parameters({'/some/path/to/something/stored':'IMPORTANT_SETTING'})importosprint(os.environ.get('IMPORTANT_SETTING'))'super-important-value'Using with python-decoupleimportosfromawstanding.parameter_storeimportload_parametersfromdecoupleimportconfigload_parameters({'/some/path/to/something/stored':'IMPORTANT_SETTING'})IMPORTANT_SETTING=config('IMPORTANT_SETTING',default='some-default')print(IMPORTANT_SETTING)'super-important-value'Not allowing missing parametersfromawstanding.parameter_storeimportload_parameters# A call like this one:load_parameters({'/not/defined/parameter':'IMPORTANT_SETTING'},allow_invalid=False)# will raise a ParameterNotFoundException, and you can handle it as follows:fromawstanding.exceptionsimportParameterNotFoundExceptiontry:load_parameters({'/not/defined/parameter':'IMPORTANT_SETTING'},allow_invalid=False)exceptParameterNotFoundExceptionase:# perform any cleanup action..PerformanceAmount of parametersMissing parametersAWStandingSSM client calls400~3.1s~15.5s400~2.4s~15.3s400~4.6s~14.5s400~2.5s~15.5s401~2.1serror: ParameterNotFound4020~2.2serror: ParameterNotFound4040~2.1serror: ParameterNotFound8040~3.5serror: ParameterNotFound8040~3.9s(using try..except) ~32.7sLoading pathsSuppose you have defined these variables in ParameterStore:'/stripe/price/''/stripe/webhook/'# (Let's not define this one just for demonstration)You can leverage on the good naming and perform a path variable loading as follows:importosfromawstanding.parameter_storeimportload_pathload_path('/stripe','/spotify')STRIPE_PRICE=os.environ.get('STRIPE_PRICE','fallback_value')STRIPE_WEBHOOK=os.environ.get('STRIPE_WEBHOOK','fallback_value')SPOTIFY_API_KEY=os.environ.get('SPOTIFY_API_KEY','fallback_value')print(f'price:{STRIPE_PRICE}, webhook:{STRIPE_WEBHOOK}, spotify:{SPOTIFY_API_KEY}')>>>price:price_1xxxxxxxxxxxxxxxxxxxxxxx,webhook:fallback_value,spotify:fallback_valueDynamic ParametersYou can define dynamic parameters that uploads themselves each time they are used, so you can update
any parameter without re-deploy your service.fromawstanding.parameter_storeimportDynamicParameterIMPORTANT_SETTING=DynamicParameter('/test/parameter')print(IMPORTANT_SETTING)>>>OriginalValue# Someone updates /test/parameter on AWS...print(IMPORTANT_SETTING)>>>NewValueSupported operationsSome useful operations are supported by the class itself, emulating built-in str class:fromawstanding.parameter_storeimportDynamicParameterIMPORTANT_SETTING=DynamicParameter('/test/parameter')# Equality comparisonequal=IMPORTANT_SETTING=='SomeString'# Lengthlength=len(IMPORTANT_SETTING)# Concatenation (Right and Left)concat='~'+IMPORTANT_SETTING+'~'# You can always convert the parameter to string to get full string capabilities:str_IMPORTANT_SETTING=str(IMPORTANT_SETTING)# Have in mind this will "freeze" the value, so don't overwrite IMPORTANT_SETTINGS3 IntegrationDownload files from S3fromawstanding.s3importBucketbucket=Bucket('BUCKET_NAME_HERE')bucket.download("path/to/file.ext",'./some/local/file.ext')Upload files to S3fromawstanding.s3importBucketbucket=Bucket('BUCKET_NAME_HERE')bucket.upload('/some/local/file.ext',"some/s3/logical/path.ext")There's not file type restriction any other that the set by AWS/boto3 itself.