Search code examples
aws-fargatepostgrest

PostgREST error on connecting in AWS using secrets


Currently deploying PostgREST in AWS. When I use Fargate and just hardcoded type in the environment variables for the connection string, the machine works like a charm. However I recently replaced these values with secrets. In the secret I copy-pasted the entire string in the value and in the environment variable I set the source from "Value" to "ValueFrom".

So the value now is:

postgres://<myuser>:<mypass>@<amazon-rds-instance>:5432/<db>

When I use this connectionstring directly in the environment variable I can easily connect, so I know the information is correct.

The logs come back with the following error:

{"details":"missing \"=\" after \"{\"postgrest_db_connection\":\"postgres://myuser:mypass@amazon-rds-instance:5432/db\"}\" in connection info string\n","code":"","message":"Database connection error"}

I also checked I have no characters in the string that need to be escaped. What can I be missing here?

enter image description here

enter image description here


Solution

  • So I figured it out. Unfortunately this line was it:

    It is only supported to inject the full contents of a secret as an environment variable. Specifying a specific JSON key or version is not supported at this time.

    This means that whenever you use the secrets as ValueFrom setting in the environment variables (when working with Fargate), the entire secret's value gets copy-pasted.

    I tested this using a secret for the PostgREST schema variable. I got back the value:

    {'PGRST_SCHEMA_URL': 'public'}
    

    Whilst I was expecting it to be just:

    public
    

    This is why the configuration went bad as well. Thanks everyone for searching.