Skip to main content

CLI for rendering configuration templates with SSM Parameter Store as a data source

Project description

SSM Parameter Store Template

Command line application to render templates with data from SSM Parameter Store

Installation

The ssm-ps-template application is available via the Python Package Index and can be installed with pip:

pip install ssm-ps-template

Templating

The application uses Jinja2 for the templating engine.

Configuration

The configuration file provides the ability to specify multiple templates, override AWS configuration, and change logging levels:

Top-Level Configuration Directives

Directive Description
templates An array of template directives as detailed in the next table.
profile Specify the AWS profile to use. If unspecified will default to the AWS_DEFAULT_PROFILE environment variable or is unspecified
region Specify the AWS region to use. If unspecified it will default to the AWS_DEFAULT_REGION environment variable or is unspecified
verbose Turn debug logging on. Possible values are true and false

Template Configuration Directives

The templates directive in the configuration is an array of objects, defined by a source and destination.

Directive Description
source The source file of the template
destination The destination path to write the rendered template to
prefix The prefix to prepend variables with if they do not start with a forward-slash (/)

Extended Templating Functionality

In addition to the base functionality exposed by Jinja2, the following Python functions have been added:

Function Definition
urlparse The urllib.parse.urlparse function from the Python standard library.
parse_qs The urllib.parse.parse_qs function from the Python standard library.
unquote The urllib.parse.unquote function from the Python standard library.

The following filters are added:

Filter Description
toyaml Converts a dictionary value to YAML

The following variables are exposed:

Variable Definition
environ The os.environ dictionary for accessing environment variables

Configuration File Format

The application supports JSON, TOML, or YAML for configuration. The following example is in YAML:

Example Configuration File

templates:
  - source: /etc/ssm-templates/nginx-example
    destination: /etc/nginx/sites-available/example
    prefix: /namespaced/application/nginx/
  - source: /etc/ssm-templates/postgres-example
    destination: /etc/postgresql/14/main/postgresql.conf
    prefix: /namespaced/application/postgres/
profile: default
region: us-east-1
verbose: false

Path Based Dictionaries

In more complex templates it's possible to need a dictionary of values from SSM instead of straight key/value usage.

This is achieved by setting a variable to a key with a trailing slash (/).

The following pattern will retrieve all keys under a path and return them as a nested dictionary with a / delimiter, and then iterate over the key/value pairs:

{% set values = settings/ %}
{% for key, value in settings.items() %}
  {{ key }}: {{ value }}
{% endfor %}

Or to convert them to YAML:

settings: {% set values = settings/ %}
{{ values | toyaml | indent(2, first=True) }}

Command Line Usage

usage: ssm-ps-template [-h] [--aws-profile AWS_PROFILE] [--aws-region AWS_REGION] [--prefix PREFIX] [--verbose] config

Templating for SSM Parameter Store

positional arguments:
  config

optional arguments:
  -h, --help            show this help message and exit
  --aws-profile AWS_PROFILE
                        AWS Profile
  --aws-region AWS_REGION
                        AWS Region
  --prefix PREFIX       Default SSM Key Prefix
  --verbose

Note that the default SSM prefix can also be set with the PARAMS_PREFIX environment variable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssm-ps-template-1.0.0b5.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

ssm_ps_template-1.0.0b5-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file ssm-ps-template-1.0.0b5.tar.gz.

File metadata

  • Download URL: ssm-ps-template-1.0.0b5.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for ssm-ps-template-1.0.0b5.tar.gz
Algorithm Hash digest
SHA256 f0233ff2d8f82e1cf402852a15ab66db77cff6cf125d9cc43de3fa357dae7611
MD5 9db88cd539805d11a9684adc1812d4b6
BLAKE2b-256 b11cff695241cb24686897a5540776bf7f0150f2540688d4f65978c2c2416bc6

See more details on using hashes here.

File details

Details for the file ssm_ps_template-1.0.0b5-py3-none-any.whl.

File metadata

File hashes

Hashes for ssm_ps_template-1.0.0b5-py3-none-any.whl
Algorithm Hash digest
SHA256 7270e81d61bb967f6dd16ee3fba3e57fb4aa9eb7dc391fd1df84b06f3eda484e
MD5 5557ad6a7b25c6e648484346249bf8b4
BLAKE2b-256 a3ade7f62eb9555a29f210d26e5dd7e07074cb54ea7dbfb392f3e285cf7a840c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page