Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PgbouncerSecret not finished updating when PgStacDatabase construct is ready to use #122

Open
hrodmn opened this issue Feb 4, 2025 · 0 comments

Comments

@hrodmn
Copy link
Contributor

hrodmn commented Feb 4, 2025

With add_pgbouncer=True, a CDK app that tries to read the secret values with something like pgstac_db.pgstac_secret.secret_value_from_json("host").to_string() will crash because the secret value has not yet been updated by the secret bootstrap function.

pgstac_db = PgStacDatabase(
    self,
    "pgstac-db",
    ...
)

# allow connections from any ipv4 to pgbouncer instance security group
assert pgstac_db.security_group
pgstac_db.security_group.add_ingress_rule(
    aws_ec2.Peer.any_ipv4(), aws_ec2.Port.tcp(5432)
)

#######################################################################
# Raster service
raster = TitilerPgstacApiLambda(
    self,
    "raster-api",
    api_env={
        "POSTGRES_HOST": pgstac_db.pgstac_secret.secret_value_from_json(
            "host"
        ).to_string(),
        "POSTGRES_DBNAME": pgstac_db.pgstac_secret.secret_value_from_json(
            "dbname"
        ).to_string(),
        "POSTGRES_USER": pgstac_db.pgstac_secret.secret_value_from_json(
            "username"
        ).to_string(),
        "POSTGRES_PASS": pgstac_db.pgstac_secret.secret_value_from_json(
            "password"
        ).to_string(),
        "POSTGRES_PORT": pgstac_db.pgstac_secret.secret_value_from_json(
            "port"
        ).to_string(),
    },
    db=pgstac_db.connection_target,
    db_secret=pgstac_db.pgstac_secret,
)

We need to have a way to create a dependency on the successful completion of the secret bootstrapping operation like the pgbouncer has for the pgstac boostrap:

this._pgBouncerServer.node.addDependency(bootstrapper);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant