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

database environment parameters in serverless.yml #3

Open
wildthing81 opened this issue Jul 17, 2019 · 4 comments
Open

database environment parameters in serverless.yml #3

wildthing81 opened this issue Jul 17, 2019 · 4 comments

Comments

@wildthing81
Copy link

wildthing81 commented Jul 17, 2019

My serverless.yml contains DB parameters like so
environment:
DB_NAME: ${self:custom.database.name}
DB_USERNAME: ${self:custom.database.username}
DB_PASSWORD: ${self:custom.database.password}
DB_HOST: ${self:custom.database.host}
DB_PORT: ${self:custom.database.port}

Will these parameters get resolved if I run 'sls migrations up' . I am currently getting a

Serverless: Setting up connections...
Serverless: Looking for pending migrations...
Serverless: Error trying to apply migrations:
SequelizeConnectionError: connect ENOENT [object Object]

@manelferreira
Copy link
Owner

Hi Ramaswamy.

From what you described, I guess that the DB_DIALECT parameter is missing.
You have to set the DB_DIALECT value as one of the options presented below, according to the database you are working with:
DB_DIALECT: 'mysql' OR 'mariadb' OR 'postgres' OR 'mssql'

If the issue persists, let me know so that I can help you.

@wildthing81
Copy link
Author

I have added the DB_DIALECT as well. still the same problem. The issue here is how to resolve DB parameters when they are dynamically generated from an RDS resource section within the same serverless yml file & stored as properties in 'custom' section of the yml ?

@GonzaloSaad
Copy link

Just encountered the same issue.

I have the following:

Resources:
  RDS:
    Type: "AWS::RDS::DBInstance"
    ...

Then, to get the endpoint and the port:

  dbEndpoint:
    "Fn::GetAtt":
      - RDS
      - Endpoint.Address

  dbPort:
    "Fn::GetAtt":
      - RDS
      - Endpoint.Port

On the environment:

  environment:
    STAGE: ${self:provider.stage}
    DB_DIALECT: 'postgres'
    DB_PROTOCOL: ${self:custom.dbProtocol}
    DB_USERNAME: ${self:custom.dbUsername}
    DB_PASSWORD: ${self:custom.dbPassword}
    DB_HOST: ${self:custom.dbEndpoint}
    DB_PORT: ${self:custom.dbPort}
    DB_NAME: ${self:custom.dbName}

Then I get:

RangeError: "port" option should be >= 0 and < 65536: NaN

Alright. Now if I hardcode the port, that error disappears, but this comes up:

SequelizeHostNotFoundError: getaddrinfo ENOTFOUND [object Object] [object Object]:5432

@jcoelho93
Copy link

I'm also getting this issue.
I have an RDS resource declared:

...
resources:
    Resources:
        RDSInstance:
              Type: AWS::RDS::DBInstance
              Properties:
...

Then I set my environment variables like this:

custom:
    databaseHost: !GetAtt RDSInstance.Endpoint.Address
...
provider:
    environment:
        DB_DIALECT: postgres
        DB_HOST: ${self:custom.databaseHost}
...

But when I run sls migrations up it always tries to connect to 127.0.0.1.
But the environment variable is set correctly, I can see in the Lambda console that the DB_HOST has the correct value.

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

4 participants