N8n in ECS Fargate - There was an error initializing DB

Describe the problem/error/question

Attempting to run n8n on ECS Fargate, however, when the container launches, the logs show the following:

“There was an error initializing DB”

I have a very basic setup in my CDK stack. Not sure if it will be helpful, but here’s what I have so far:

    // RDS PostgreSQL (must be defined before it's referenced)
    const db = new rds.DatabaseInstance(this, 'N8nDb', {
      engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_15_7 }),
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.MICRO),
      vpc,
      vpcSubnets: { subnetGroupName: 'DbSubnet' },
      securityGroups: [dbSG],
      credentials: rds.Credentials.fromPassword('n8n', cdk.SecretValue.unsafePlainText('myn8npasswordhere')),
      databaseName: 'n8n',
      publiclyAccessible: false,
      multiAz: false,
      allocatedStorage: 20,
      maxAllocatedStorage: 100,
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      deletionProtection: false,
    });

    taskDef.addContainer('N8nContainer', {
      image: ecs.ContainerImage.fromRegistry('n8nio/n8n'),
      environment: {
        N8N_BASIC_AUTH_ACTIVE: 'true',
        N8N_BASIC_AUTH_USER: n8nAuthSecret.secretValueFromJson('user').unsafeUnwrap(),
        N8N_BASIC_AUTH_PASSWORD: n8nAuthSecret.secretValueFromJson('password').unsafeUnwrap(),
        N8N_DIAGNOSTICS_ENABLED: 'false',
        N8N_LOG_LEVEL: 'debug',
        DB_TYPE: 'postgresdb',
        DB_POSTGRESDB_HOST: db.dbInstanceEndpointAddress,
        DB_POSTGRESDB_PORT: '5432',
        DB_POSTGRESDB_DATABASE: 'n8n',
        DB_POSTGRESDB_USER: 'n8n',
        DB_POSTGRESDB_PASSWORD: 'myn8npassword',
        DB_POSTGRESDB_SSL_ENABLED: 'true',

What is the error message (if any)?

“There was an error initializing DB”

Please share your workflow

NA

Share the output returned by the last node

Information on your n8n setup

  • n8n version: latest
  • Database (default: SQLite): AWS RDS - PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): NA
  • Running n8n via (Docker, npm, n8n cloud, desktop app): AWS ECS Fargate (Docker)
  • Operating system: Amazon Linux 2

I added the code I have for the DB setup above.

Here are some more verbose logs. I can’t seem to pinpoint the issue. There are other posts on this forum about errors initializing the DB, however, their errors are more specific (credentials issues, database connection issues, etc).

There was an error initializing DB  {"file":"error-reporter.js","function":"defaultReport"}
self-signed certificate in certificate chain {"file":"error-reporter.js","function":"defaultReport"}
Lazy-loading nodes and credentials from @n8n/n8n-nodes-langchaine[39m {"nodes":92,"credentials":21,"file":"lazy-package-directory-loader.js","function":"loadAll"}
Lazy-loading nodes and credentials from n8n-nodes-basee[39m {"nodes":480,"credentials":383,"file":"lazy-package-directory-loader.js","function":"loadAll"}
Initializing n8n processe[39m {"file":"start.js","function":"init"}
Permissions 0644 for n8n settings file /home/node/.n8n/config are too wide. This is ignored for now, but in the future n8n will attempt to change the permissions automatically. To automatically enforce correct permissions now set N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true (recommended), or turn this check off set N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=false.e[39m {"file":"instance-settings.js","function":"ensureSettingsFilePermissions"}
No encryption key found - Auto-generating and saving to: /home/node/.n8n/confige {"file":"instance-settings.js","function":"loadOrCreate"}

hello @minerva

seems the n8n doesn’t trust the DB certificate

check the docs on how to trust custom certificates
Configure n8n to use your own certificate authority | n8n Docs

And you can ignore the variables N8N_BASIC_AUTH* as they have no effect

1 Like

Thanks for the quick reply. I’m trying to get this stood up behind an ALB using AWS’ ACM (Certificate Manager).

I’m not totally sure how to fix the issue. I’ll review the doc to try and sort it out, though.

If there’s anyone else who has launched this on ECS Fargate, I’d love to hear from you.

You can upload the CA from the ACM locally to the n8n volume and mount it as the /opt/custom-certificates path

1 Like