Skip to main content

A utility for resolving ssm parameters and secretsmanager secrets

Project description

ENV Resolver (Python)

This is a small utility to resolve SSM Parameters and Secretsmanager Secrets and conditionally set them in the environment.

This is helpful for services like AWS Batch or AWS Lambda where there is not a way natively to pass secret values.

Install

pip install env-resolver

This package assumes that you already depend on boto3 and have it installed as a dependency of your project. If you are using this package in AWS Lambda, boto3 will already be available.

Quick Start

Parameter Store

from parameter_resolver import resolve

# assuming you've created two parameters:
# ssm/parameter/env-one = val-one
# ssm/parameter/env-two = val-two

parameters = {
    'ENV_ONE': 'ssm/parameter/env-one',
    'ENV_TWO': 'ssm/parameter/env-two'
}

print(resolve('ssm', parameters))

# Outputs:
# {
#     'ENV_ONE': 'val-one',
#     'ENV_TWO': 'val-two'
# }

Secrets Manager

from parameter_resolver import resolve

# assuming you've created the following secret:
# secret/secret-one =
# {
#     'ENV_ONE': 'val-one',
#     'ENV_TWO': 'val-two'
# }

secret = {
    'secret_id': 'secret/secret-one'
}

print(resolve('secretsmanager', secret))

# Outputs:
# {
#     'ENV_ONE': 'val-one',
#     'ENV_TWO': 'val-two'
# }

Usage

resolve(parameter_type, parameter_value, set_environment_variables=True)

These are the possible values for parameter_type:

  • ssm
  • secretsmanager

Options

The set_environment_variables options allows you to choose whether or not to set the new key-value pairs in the environment.

SSM

For a parameter store parameter, resolve expects the parameter_value to be a dictionary of KEY: PARAMETER_NAME.

Secretsmanager

For a secretsmanager secret, resolve expects the parameter_value to be a dictionary with the following possible values:

secret = {
    'secret_id': 'string',
    'version_id': 'string', # optional
    'json_value': 'boolean' # option, default=True
}

Contributing

PR's are welcome!

This project uses Poetry for dependency / environment management.

Install Dependencies

poetry install

Tests

poetry run pytest

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

env_resolver-0.1.7.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

env_resolver-0.1.7-py3-none-any.whl (2.9 kB view hashes)

Uploaded Python 3

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