# croudtech-python-aws-app-config
croudtech-python-aws-app-config us a utility to help manage application config using the AWS SSM Parameter Store
There is a cli tool to help set the values and a utility to use the SSM parameters within you application.
## Installation
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install croudtech-python-aws-app-config.
```bash
pip install croudtech-python-aws-app-config
```
## Command Line Usage
```
Usage: cli.py [OPTIONS] COMMAND [ARGS]...
Options:
--debug / --no-debug
--endpoint-url TEXT
--help Show this message and exit.
Commands:
delete-parameters
get-arns
get-parameters
put-parameters
put-parameters-recursive
manage-redis
```
--endpoint-url specified the AWS API endpoint URL used. This should be used if using localstack or a similar aws mock service. You can also set the `AWS_ENDPOINT_URL` env var to enable this feature.
### Sub Commands
#### delete-parameters
Delete parameters from SSM for a specified app and environment
```
Usage: cli.py delete-parameters [OPTIONS]
Options:
--environment-name TEXT The environment name [required]
--app-name TEXT The app name [required]
--ssm-prefix TEXT The ssm path prefix
--region TEXT The AWS region
--help Show this message and exit.
```
#### get-arns
Get ARNs for published parameters
```
Usage: cli.py get-arns [OPTIONS]
Options:
--environment-name TEXT The environment name [required]
--app-name TEXT The app name [required]
--ssm-prefix TEXT The ssm path prefix
--region TEXT The AWS region
--include-common / --ignore-common
Include shared variables
--output-format [ecs]
--help Show this message and exit.
```
#### get-parameters
Get parameters for a specific app and environment
```
Usage: cli.py get-parameters [OPTIONS]
Options:
--environment-name TEXT The environment name [required]
--app-name TEXT The app name [required]
--ssm-prefix TEXT The ssm path prefix
--region TEXT The AWS region
--include-common / --ignore-common
Include shared variables
--output-format [json|yaml|environment|environment-export]
--help Show this message and exit.
```
You can export the variables to your local shell by using
```
eval $(croudtech-app-config get-parameters --app-name myapp --environment-name myenv --output-format environment-export)
```
#### put-parameters
INPUT should be the path to a yaml or json file
```
Usage: cli.py put-parameters [OPTIONS] INPUT
Options:
--environment-name TEXT The environment name [required]
--app-name TEXT The app name [required]
--ssm-prefix TEXT The ssm path prefix
--region TEXT The AWS region
--encrypted TEXT Do you want these parameters to be encrypted?
--delete-first Delete the values in this path before pushing
(useful for cleanup)
--help Show this message and exit.
```
#### put-parameters-recursive
Recursively put parameters from a directory with the following structure
```
├── EnvironmentName1
│ ├── AppName1.yaml
│ ├── AppName1.secret.yaml
│ ├── AppName2.yaml
│ └──AppName2.secret.yaml
└── EnvironmentName2
├── AppName1.yaml
├── AppName1.secret.yaml
├── AppName2.yaml
└──AppName2.secret.yaml
```
Files with a *secret.yaml* or *secret.json* suffix will have the parameters encrypted in SSM.
```
Usage: cli.py put-parameters-recursive [OPTIONS] VALUES_PATH
Options:
--ssm-prefix TEXT The ssm path prefix
--region TEXT The AWS region
--delete-first Delete the values in this path before pushing (useful for
cleanup)
--help Show this message and exit.
```
## Managing Redis DB Allocation
Manage redis DB allocation
### Sub commands
#### allocate-db
```
Usage: python -m croudtech_python_aws_app_config.cli manage-redis allocate-db
[OPTIONS]
Allocate a Redis database for a specified application and environment
Options:
--redis-host TEXT The redis host [required]
--redis-port INTEGER The redis port [required]
--environment-name TEXT The environment name [required]
--app-name TEXT The application name [required]
--help Show this message and exit.
```
#### deallocate-db
```
Usage: python -m croudtech_python_aws_app_config.cli manage-redis deallocate-db
[OPTIONS]
Remove Redis database allocation for the specified application and
environment
Options:
--redis-host TEXT The redis host [required]
--redis-port INTEGER The redis port [required]
--environment-name TEXT The environment name [required]
--app-name TEXT The application name [required]
--help Show this message and exit.
```
#### show-db
```
Usage: python -m croudtech_python_aws_app_config.cli manage-redis show-db
[OPTIONS]
Show Allocated Redis Database for a specified application
Options:
--environment-name TEXT The environment name [required]
--app-name TEXT The app name [required]
--ssm-prefix TEXT The ssm path prefix
--region TEXT The AWS region
--include-common / --ignore-common
Include shared variables
--help Show this message and exit.
```
#### show-dbs
```
Usage: python -m croudtech_python_aws_app_config.cli manage-redis show-dbs
[OPTIONS]
Show all allocated Redis databases
Options:
--redis-host TEXT The redis host [required]
--redis-port INTEGER The redis port [required]
--help Show this message and exit.
```
## Nested file structure and environment variables
Nested values will have their keys flattened when being converted to environment variables. This allows for a simpler structure than just adding all your env vars separately.
For example:
```
SOME_VARIABLE: test
ANOTHER_VAR: 123
SOME_OTHER_VAR: foo
CONNECTIONS:
POSTGRESS:
HOST: somehost
PORT: 1234
USERNAME: someuser
PASSWORD: somepass
```
Would translate into the following environment variables:
```
SOME_VARIABLE="test"
ANOTHER_VAR="123"
SOME_OTHER_VAR="foo"
CONNECTIONS_POSTGRESS_HOST="somehost"
CONNECTIONS_POSTGRESS_PORT="1234"
CONNECTIONS_POSTGRESS_USERNAME="someuser"
CONNECTIONS_POSTGRESS_PASSWORD="somepass"
```
## Usage in application code
In the top of your application bootstrap file (or settings.py in django) add:
```
from croudtech_python_aws_app_config.ssm_config import SsmConfig
ssm_config = SsmConfig(
environment_name=os.environ.get("ENVIRONMENT_NAME"), app_name=os.environ.get("APP_NAME")
)
ssm_config.params_to_env()
```
Make sure your ENVIRONMENT_NAME and APP_NAME env vars are set.
This will pull values from SSM and inject them into your application environment variables.
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Raw data
{
"_id": null,
"home_page": null,
"name": "croudtech-python-aws-app-config",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": null,
"author": "Jim Robinson",
"author_email": "jim.robinson@croud.com",
"download_url": "https://files.pythonhosted.org/packages/a3/bb/97b5c32b575c434e4694a9afa43a69e34620f213d5ad486d052bb3e0b002/croudtech_python_aws_app_config-2.0.2.tar.gz",
"platform": null,
"description": "# croudtech-python-aws-app-config\n\ncroudtech-python-aws-app-config us a utility to help manage application config using the AWS SSM Parameter Store\n\nThere is a cli tool to help set the values and a utility to use the SSM parameters within you application.\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install croudtech-python-aws-app-config.\n\n```bash\npip install croudtech-python-aws-app-config\n```\n\n## Command Line Usage\n\n```\nUsage: cli.py [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n --debug / --no-debug\n --endpoint-url TEXT\n --help Show this message and exit.\n\nCommands:\n delete-parameters\n get-arns\n get-parameters\n put-parameters\n put-parameters-recursive\n manage-redis\n```\n\n--endpoint-url specified the AWS API endpoint URL used. This should be used if using localstack or a similar aws mock service. You can also set the `AWS_ENDPOINT_URL` env var to enable this feature.\n\n### Sub Commands\n\n#### delete-parameters\n\nDelete parameters from SSM for a specified app and environment\n\n```\nUsage: cli.py delete-parameters [OPTIONS]\n\nOptions:\n --environment-name TEXT The environment name [required]\n --app-name TEXT The app name [required]\n --ssm-prefix TEXT The ssm path prefix\n --region TEXT The AWS region\n --help Show this message and exit.\n```\n\n#### get-arns\n\nGet ARNs for published parameters\n\n```\nUsage: cli.py get-arns [OPTIONS]\n\nOptions:\n --environment-name TEXT The environment name [required]\n --app-name TEXT The app name [required]\n --ssm-prefix TEXT The ssm path prefix\n --region TEXT The AWS region\n --include-common / --ignore-common\n Include shared variables\n --output-format [ecs]\n --help Show this message and exit.\n```\n\n#### get-parameters\n\nGet parameters for a specific app and environment\n\n```\nUsage: cli.py get-parameters [OPTIONS]\n\nOptions:\n --environment-name TEXT The environment name [required]\n --app-name TEXT The app name [required]\n --ssm-prefix TEXT The ssm path prefix\n --region TEXT The AWS region\n --include-common / --ignore-common\n Include shared variables\n --output-format [json|yaml|environment|environment-export]\n --help Show this message and exit.\n```\n\nYou can export the variables to your local shell by using\n\n```\neval $(croudtech-app-config get-parameters --app-name myapp --environment-name myenv --output-format environment-export)\n```\n#### put-parameters\n\nINPUT should be the path to a yaml or json file\n\n```\nUsage: cli.py put-parameters [OPTIONS] INPUT\n\nOptions:\n --environment-name TEXT The environment name [required]\n --app-name TEXT The app name [required]\n --ssm-prefix TEXT The ssm path prefix\n --region TEXT The AWS region\n --encrypted TEXT Do you want these parameters to be encrypted?\n --delete-first Delete the values in this path before pushing\n (useful for cleanup)\n\n --help Show this message and exit.\n```\n\n#### put-parameters-recursive\n\nRecursively put parameters from a directory with the following structure\n\n```\n\u251c\u2500\u2500 EnvironmentName1\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 AppName1.yaml\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 AppName1.secret.yaml\n\u2502 \u251c\u2500\u2500 AppName2.yaml\n\u2502\u00a0\u00a0 \u2514\u2500\u2500AppName2.secret.yaml\n\u2514\u2500\u2500 EnvironmentName2\n \u00a0\u00a0 \u251c\u2500\u2500 AppName1.yaml\n \u00a0\u00a0 \u251c\u2500\u2500 AppName1.secret.yaml\n \u251c\u2500\u2500 AppName2.yaml\n \u00a0\u00a0 \u2514\u2500\u2500AppName2.secret.yaml\n```\n\nFiles with a *secret.yaml* or *secret.json* suffix will have the parameters encrypted in SSM.\n\n```\nUsage: cli.py put-parameters-recursive [OPTIONS] VALUES_PATH\n\nOptions:\n --ssm-prefix TEXT The ssm path prefix\n --region TEXT The AWS region\n --delete-first Delete the values in this path before pushing (useful for\n cleanup)\n\n --help Show this message and exit.\n```\n\n## Managing Redis DB Allocation\n\nManage redis DB allocation\n\n### Sub commands\n\n#### allocate-db\n\n```\nUsage: python -m croudtech_python_aws_app_config.cli manage-redis allocate-db\n [OPTIONS]\n\n Allocate a Redis database for a specified application and environment\n\nOptions:\n --redis-host TEXT The redis host [required]\n --redis-port INTEGER The redis port [required]\n --environment-name TEXT The environment name [required]\n --app-name TEXT The application name [required]\n --help Show this message and exit.\n```\n\n#### deallocate-db\n```\nUsage: python -m croudtech_python_aws_app_config.cli manage-redis deallocate-db\n [OPTIONS]\n\n Remove Redis database allocation for the specified application and\n environment\n\nOptions:\n --redis-host TEXT The redis host [required]\n --redis-port INTEGER The redis port [required]\n --environment-name TEXT The environment name [required]\n --app-name TEXT The application name [required]\n --help Show this message and exit.\n```\n#### show-db\n```\nUsage: python -m croudtech_python_aws_app_config.cli manage-redis show-db\n [OPTIONS]\n\n Show Allocated Redis Database for a specified application\n\nOptions:\n --environment-name TEXT The environment name [required]\n --app-name TEXT The app name [required]\n --ssm-prefix TEXT The ssm path prefix\n --region TEXT The AWS region\n --include-common / --ignore-common\n Include shared variables\n --help Show this message and exit.\n```\n#### show-dbs\n```\nUsage: python -m croudtech_python_aws_app_config.cli manage-redis show-dbs\n [OPTIONS]\n\n Show all allocated Redis databases\n\nOptions:\n --redis-host TEXT The redis host [required]\n --redis-port INTEGER The redis port [required]\n --help Show this message and exit.\n```\n\n## Nested file structure and environment variables\n\nNested values will have their keys flattened when being converted to environment variables. This allows for a simpler structure than just adding all your env vars separately.\n\nFor example:\n\n```\nSOME_VARIABLE: test\nANOTHER_VAR: 123\nSOME_OTHER_VAR: foo\nCONNECTIONS:\n POSTGRESS:\n HOST: somehost\n PORT: 1234\n USERNAME: someuser\n PASSWORD: somepass\n```\n\nWould translate into the following environment variables:\n\n```\nSOME_VARIABLE=\"test\"\nANOTHER_VAR=\"123\"\nSOME_OTHER_VAR=\"foo\"\nCONNECTIONS_POSTGRESS_HOST=\"somehost\"\nCONNECTIONS_POSTGRESS_PORT=\"1234\"\nCONNECTIONS_POSTGRESS_USERNAME=\"someuser\"\nCONNECTIONS_POSTGRESS_PASSWORD=\"somepass\"\n```\n\n## Usage in application code\n\nIn the top of your application bootstrap file (or settings.py in django) add:\n\n```\nfrom croudtech_python_aws_app_config.ssm_config import SsmConfig\n\nssm_config = SsmConfig(\n environment_name=os.environ.get(\"ENVIRONMENT_NAME\"), app_name=os.environ.get(\"APP_NAME\")\n)\nssm_config.params_to_env()\n```\n\nMake sure your ENVIRONMENT_NAME and APP_NAME env vars are set.\n\nThis will pull values from SSM and inject them into your application environment variables.\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "2.0.2",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a8eea6918af12a43f395fc67aa099f728f0d7bf986f1d04cb7dcc7e190a8f970",
"md5": "e28a70fe6fae3d230428b71683592b5f",
"sha256": "cd00be9485d31e64b2a6f38c4f2b17026ecbce8856e1b154bf5f5c14b0914cd7"
},
"downloads": -1,
"filename": "croudtech_python_aws_app_config-2.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e28a70fe6fae3d230428b71683592b5f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 14311,
"upload_time": "2024-05-15T15:28:44",
"upload_time_iso_8601": "2024-05-15T15:28:44.596089Z",
"url": "https://files.pythonhosted.org/packages/a8/ee/a6918af12a43f395fc67aa099f728f0d7bf986f1d04cb7dcc7e190a8f970/croudtech_python_aws_app_config-2.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a3bb97b5c32b575c434e4694a9afa43a69e34620f213d5ad486d052bb3e0b002",
"md5": "e02301c97e0799520744f4bc711062ab",
"sha256": "988e84cf6a1a3418405e6c87ce90df67e8f97b6d3b345dba1baae38b393353d3"
},
"downloads": -1,
"filename": "croudtech_python_aws_app_config-2.0.2.tar.gz",
"has_sig": false,
"md5_digest": "e02301c97e0799520744f4bc711062ab",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 12554,
"upload_time": "2024-05-15T15:28:45",
"upload_time_iso_8601": "2024-05-15T15:28:45.795517Z",
"url": "https://files.pythonhosted.org/packages/a3/bb/97b5c32b575c434e4694a9afa43a69e34620f213d5ad486d052bb3e0b002/croudtech_python_aws_app_config-2.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-15 15:28:45",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "croudtech-python-aws-app-config"
}