Package: psenv
psenv -- (Parameter Store Environment)a cli tool for managing environments stored in the AWS parameter storeWhen working on teams with multiple developers, who may each have their own local development environment,
it can be challenging to make sure that each environment has the same set of base parameter values in a.envfile to get the base project up and running. It can be common that as a project grows over time, there can be 100s
of environment variables which contain everything from project configuration values, to database connection strings,
or even secret API keys and tokens.Sometimes developers may need to keep multiple.envfiles locally for different projects, each of which may have a
different set of parameters. This can become quite difficult to manage across multiple medium to large size teams.
This is wherepsenvcomes in, to help those of us who are working within the AWS cloud ecosystem.Getting Startedpip install psenvHowever, sincepsenvworks well as a globally available command, the preferred method of installation is to usepipxpipx install psenv --include-depsFor those of you who are unfamiliar withpipx, it can be thought of as a "Homebrew for python applications".Check out the amazing project here ---->>>https://pypa.github.io/pipx/docs/InitializationAfter installation,psenvneeds to be initialized and configured. To speed this up you can runpsenvinitThis will create a directory at~/.psenvand a config file at~/.psenv/psenv.ymlas well as an environment file~/.psenv/psenv.envSetting Up An EnvironmentOpen the~/.psenv/psenv.ymlfile in your editor of choice and make an entry.environments:my_project_name:path:/the/path/used/in-the/aws/parameter-storeenv:/path/to/local/env/file/.envTheenvironmentskey is a list, which can take as many environment definitions as you like.CommandsAt any time you can typepsenv --helpfor a list of commands.psenv--help
psenv<command>--helpDisplaying Configured EnvironmentsTo display the environments configuredpsenvshowYou should see a list of all available environments formatted in your terminal as a table. This can come in handy as we
will later need to reference the configured environments for the other commandsFetch an Environment from the AWS Parameter StoreThis command will fetch all the parameters on the path configured in thepathsection of thepsenv.ymlfilepsenvfetch--envmy_project_namePush and Environment to the AWS Parameter StoreSometimes you need to set up new environments. This is easy withpsenvadd an entry inpsenv.ymlenvironments:new_env:path:/some/parameter-store/pathenv:/path/to/.envpopulate the .env file with the secrets and parameters you need for your environment and then runpsenvpush--envnew_envPrivate Environment VariablesSometimes a project my have some environment variable where the value is known up-front. (eg. Project Configs), however there
may be some values which need to remain secret. After all, it would not make much sense for a developer to store there personal
github token in the parameter store for others to copy and use. For this case we have the#<private>section in the.envfile.All variables declared under the#<private>section in the.envfile will be ignored automatically bypsenvCredential InjectionSometimes you might want to copy some environment variables from your current terminal session environment to a .env file.
Example when you use temp AWS credentials and need to load them into more than one project / environment. To do this, get your creds however you normally would
and thenpsenvinject--prefixaws--envsome_envall your aws credentials will be injected to your .env file! Like Magic!Variable TemplatingWhen configuring an environment to be shared, it is sometimes helpful to give developers hints as to what type of private
credentials will be needed to get the code to behave as expected. This is where templating comes in.psenvallows you to define a placeholder in your.envfile using the prefixPSENV__TEMPLATE__that will be templated upon running thefetchcommand.
For example, we have a project that requires a github token, and we want to make this obvious for the next developer we onboard. In our source.envfile,
we simply declare a variable calledPSENV__TEMPLATE__GITHUB_TOKEN. We then runpsenv push --env <your-env>to push these values to the parameter store.SOME_VARIABLE1=123
SOME_VARIABLE2=234

PSENV__TEMPLATE__GITHUB_TOKEN=<REPLACE-WITH-YOUR-PERSONAL-GH-TOKEN>The next developer we on-board simply needs to runpsenv fetch --env <your-env>and the below will be created.SOME_VARIABLE1=123
SOME_VARIABLE2=234

#<private>
GITHUB_TOKEN=<REPLACE-WITH-YOUR-PERSONAL-GH-TOKEN>If you would like to fetch the environment values without using the template function, you can pass the--no-templateflag to the fetch
command, which will then fetch the raw parameters as they were created. This is useful if an admin needs to add, or remove some parameter
from an environment.