How to generate a database URI from an AWS Secret

A quick note about how to generate a database URI (or any other derived string) from an AWS SecretsManager SecretTargetAttachment (such as what's provided via a RDS DatabaseInstance's secret property).

db = rds.DatabaseInstance(
    # ...
)
db_val = lambda field: db.secret.secret_value_from_json(field).to_string()
task_definition.add_container(
    environment=dict(
        # ...
        PGRST_DB_URI=f"postgres://{db_val('username')}:{db_val('password')}@{db_val('host')}:{db_val('port')}/",
    ),
    # ...
)

blog comments powered by Disqus

Discussion, links, and tweets

You can find me on Github under the username alukach, rarely tweeting as anthonylukach, lurking in the #cugos channel on IRC's Freenode network under the name anth0ny, or by old-fashioned email at anthonylukach@gmail.com.