Can't connect to AWS RDS DB during build

Netlify site name: ecstatic-bhaskara-0b4b8a

I’m trying to deploy a postgraphile instance as a netlify function and I’ve hit a number of hurdles, the latest being that it seems that the build process times out connecting to an aws rds instance, and possibly also when the function is deployed to lambda.

I’m able to run netlify dev locally (connecting to the same aws rds instance) and it works fine. I’m using the same pg connection string both locally and in the netlify deploy (tried both hardcoding it and setting it as an env var, both same results).

Full log at the bottom of this post, but the relevant portion is this:
9:29:25 AM: Error: connect ETIMEDOUT 54.215.126.234:5432
9:29:25 AM: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
9:29:25 AM: errno: ‘ETIMEDOUT’,
9:29:25 AM: code: ‘ETIMEDOUT’,
9:29:25 AM: syscall: ‘connect’,
9:29:25 AM: address: ‘54.215.126.234’,
9:29:25 AM: port: 5432

I can confirm that the address it’s timing out on corresponds to the rds host decoded-dev.ccds2q3g2i9m.us-west-1.rds.amazonaws.com (omitted full pg connection string for this post). I can certainly connect to it from my laptop without being on any vpn or anything.
(try nc -vz decoded-dev.ccds2q3g2i9m.us-west-1.rds.amazonaws.com 5432)

For context, I’m basically trying to replicate this repo, but make it work for netlify: GitHub - graphile/postgraphile-lambda-example: Simple serverless / Lambda example with caching and lightweight bundle

I was able to successfully deploy and hit the function endpoint, but it timed out and it wasn’t clear why. It could have been because postgraphile reads the database to determine the schema on startup and that was taking too long, but it also could have just timed out connecting to the database.

In any case I tried to address this issue with my own version of this:

Basically, it’s a script that runs at build time to generate a cache of the database schema, saved in the build output dir, to be used by the function as a read cache so to avoid that step at runtime. Again, this works fine for me locally using netlify dev. (can confirm the build step proceeds normally, the cache file is generated, and the function works when run).

Is there any reason this is happening? Trying to poke at it more, but presently stuck on this.

9:27:56 AM: Waiting for other deploys from your team to complete
9:28:19 AM: Build ready to start
9:28:20 AM: build-image version: 3571f0130496395a23bffe9820bc78b4f73a6234
9:28:20 AM: build-image tag: v3.7.0
9:28:20 AM: buildbot version: c469f7ab4d394d961ca036b1163fdbb6ef9fb78c
9:28:20 AM: Fetching cached dependencies
9:28:21 AM: Starting to download cache of 91.3MB
9:28:21 AM: Finished downloading cache in 705.633404ms
9:28:21 AM: Starting to extract cache
9:28:24 AM: Finished extracting cache in 2.900653497s
9:28:24 AM: Finished fetching cache in 3.62940702s
9:28:24 AM: Starting to prepare the repo for build
9:28:25 AM: Preparing Git Reference refs/heads/master
9:28:26 AM: Different functions path detected, going to use the one specified in the Netlify configuration file: ‘functions-build’ versus ‘’ in the Netlify UI
9:28:26 AM: Starting build script
9:28:26 AM: Installing dependencies
9:28:26 AM: Python version set to 2.7
9:28:27 AM: Started restoring cached node version
9:28:30 AM: Finished restoring cached node version
9:28:30 AM: v12.18.0 is already installed.
9:28:31 AM: Now using node v12.18.0 (npm v6.14.4)
9:28:31 AM: Started restoring cached build plugins
9:28:31 AM: Finished restoring cached build plugins
9:28:31 AM: Attempting ruby version 2.7.1, read from environment
9:28:32 AM: Using ruby version 2.7.1
9:28:32 AM: Using PHP version 5.6
9:28:32 AM: Started restoring cached yarn cache
9:28:32 AM: Finished restoring cached yarn cache
9:28:33 AM: Started restoring cached node modules
9:28:33 AM: Finished restoring cached node modules
9:28:33 AM: Installing NPM modules using Yarn version 1.22.4
9:28:33 AM: yarn install v1.22.4
9:28:33 AM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
9:28:33 AM: [1/4] Resolving packages…
9:28:34 AM: [2/4] Fetching packages…
9:28:42 AM: info fsevents@2.3.2: The platform “linux” is incompatible with this module.
9:28:42 AM: info “fsevents@2.3.2” is an optional dependency and failed compatibility check. Excluding it from installation.
9:28:42 AM: info fsevents@1.2.13: The platform “linux” is incompatible with this module.
9:28:42 AM: info “fsevents@1.2.13” is an optional dependency and failed compatibility check. Excluding it from installation.
9:28:42 AM: [3/4] Linking dependencies…
9:28:42 AM: warning “postgraphile > graphile-utils@4.11.2” has unmet peer dependency “graphile-build@^4.5.0”.
9:28:42 AM: warning “postgraphile > graphile-utils@4.11.2” has unmet peer dependency “graphile-build-pg@^4.5.0”.
9:28:45 AM: [4/4] Building fresh packages…
9:28:45 AM: success Saved lockfile.
9:28:45 AM: Done in 11.93s.
9:28:45 AM: NPM modules installed using Yarn
9:28:45 AM: Started restoring cached go cache
9:28:45 AM: Finished restoring cached go cache
9:28:46 AM: go version go1.14.4 linux/amd64
9:28:46 AM: go version go1.14.4 linux/amd64
9:28:46 AM: Installing missing commands
9:28:46 AM: Verify run directory
9:28:47 AM: ​
9:28:47 AM: ────────────────────────────────────────────────────────────────
9:28:47 AM: Netlify Build
9:28:47 AM: ────────────────────────────────────────────────────────────────
9:28:47 AM: ​
9:28:47 AM: ❯ Version
9:28:47 AM: @netlify/build 9.9.5
9:28:47 AM: ​
9:28:47 AM: ❯ Flags
9:28:47 AM: apiHost: api.netlify.com
9:28:47 AM: cacheDir: /opt/build/cache
9:28:47 AM: deployId: 604ba49c5c04640008aec622
9:28:47 AM: mode: buildbot
9:28:47 AM: testOpts:
9:28:47 AM: silentLingeringProcesses: ‘’
9:28:47 AM: ​
9:28:47 AM: ❯ Current directory
9:28:47 AM: /opt/build/repo
9:28:47 AM: ​
9:28:47 AM: ❯ Config file
9:28:47 AM: /opt/build/repo/netlify.toml
9:28:47 AM: ​
9:28:47 AM: ❯ Context
9:28:47 AM: production
9:28:47 AM: ​
9:28:47 AM: ────────────────────────────────────────────────────────────────
9:28:47 AM: 1. Build command from Netlify app
9:28:47 AM: ────────────────────────────────────────────────────────────────
9:28:47 AM: ​
9:28:47 AM: $ npm run build
9:28:48 AM: > decoded-db@1.0.0 build /opt/build/repo
9:28:48 AM: > netlify-lambda build functions --config webpack.config.js && node src/makeCache.js
9:28:48 AM: netlify-lambda: Building functions
9:28:52 AM: Hash: b0e650d3c8ca906c0f9f
9:28:52 AM: Version: webpack 4.46.0
9:28:52 AM: Time: 3690ms
9:28:52 AM: Built at: 03/12/2021 5:28:52 PM
9:28:52 AM: Asset Size Chunks Chunk Names
9:28:52 AM: graphql.js 4.01 MiB 0 [emitted] graphql
9:28:52 AM: hello.js 4.19 KiB 1 [emitted] hello
9:28:52 AM: Entrypoint graphql = graphql.js
9:28:52 AM: Entrypoint hello = hello.js
9:28:52 AM: [29] external “events” 42 bytes {0} [built]
9:28:52 AM: [43] external “path” 42 bytes {0} [built]
9:28:52 AM: [58] …/node_modules/postgraphile-core/node8plus/index.js 13.5 KiB {0} [built]
9:28:52 AM: [308] ./graphql.js 742 bytes {0} [built]
9:28:52 AM: [310] …/node_modules/express/index.js 224 bytes {0} [built]
9:28:52 AM: [311] …/node_modules/express/lib/express.js 2.35 KiB {0} [built]
9:28:52 AM: [386] …/node_modules/postgraphile/index.js 141 bytes {0} [built]
9:28:52 AM: [387] …/node_modules/postgraphile/isTurbo.js 359 bytes {0} [built]
9:28:52 AM: [388] …/node_modules/postgraphile/build-turbo/index.js 5.28 KiB {0} [built]
9:28:52 AM: [644] …/node_modules/postgraphile/build/index.js 5.28 KiB {0} [built]
9:28:52 AM: [676] …/node_modules/serverless-http/serverless-http.js 659 bytes {0} [built]
9:28:52 AM: [677] …/node_modules/serverless-http/lib/finish.js 847 bytes {0} [built]
9:28:52 AM: [678] …/node_modules/serverless-http/lib/framework/get-framework.js 1.49 KiB {0} [built]
9:28:52 AM: [679] …/node_modules/serverless-http/lib/provider/get-provider.js 286 bytes {0} [built]
9:28:52 AM: [687] ./hello.js 566 bytes {1} [built]
9:28:52 AM: + 680 hidden modules
9:28:52 AM: WARNING in …/node_modules/express/lib/view.js 81:13-25
9:28:52 AM: Critical dependency: the request of a dependency is an expression
9:28:52 AM: @ …/node_modules/express/lib/application.js
9:28:52 AM: @ …/node_modules/express/lib/express.js
9:28:52 AM: @ …/node_modules/express/index.js
9:28:52 AM: @ ./graphql.js
9:28:52 AM: WARNING in …/node_modules/subscriptions-transport-ws/node_modules/ws/lib/buffer-util.js
9:28:52 AM: Module not found: Error: Can’t resolve ‘bufferutil’ in ‘/opt/build/repo/node_modules/subscriptions-transport-ws/node_modules/ws/lib’ @ …/node_modules/subscriptions-transport-ws/node_modules/ws/lib/buffer-util.js
9:28:52 AM: @ …/node_modules/subscriptions-transport-ws/node_modules/ws/lib/receiver.js
9:28:52 AM: @ …/node_modules/subscriptions-transport-ws/node_modules/ws/index.js
9:28:52 AM: @ …/node_modules/subscriptions-transport-ws/dist/server.js
9:28:52 AM: @ …/node_modules/subscriptions-transport-ws/dist/index.js
9:28:52 AM: @ …/node_modules/postgraphile/build/postgraphile/http/subscriptions.js
9:28:52 AM: @ …/node_modules/postgraphile/build/postgraphile/index.js
9:28:52 AM: @ …/node_modules/postgraphile/build/index.js
9:28:52 AM: @ …/node_modules/postgraphile/index.js
9:28:52 AM: @ ./graphql.js
9:28:52 AM: WARNING in …/node_modules/ws/lib/buffer-util.js
9:28:52 AM: Module not found: Error: Can’t resolve ‘bufferutil’ in ‘/opt/build/repo/node_modules/ws/lib’ @ …/node_modules/ws/lib/buffer-util.js
9:28:52 AM: @ …/node_modules/ws/lib/websocket.js
9:28:52 AM: @ …/node_modules/ws/index.js
9:28:52 AM: @ …/node_modules/postgraphile/build/postgraphile/http/subscriptions.js
9:28:52 AM: @ …/node_modules/postgraphile/build/postgraphile/index.js
9:28:52 AM: @ …/node_modules/postgraphile/build/index.js
9:28:52 AM: @ …/node_modules/postgraphile/index.js
9:28:52 AM: @ ./graphql.js
9:28:52 AM: WARNING in …/node_modules/subscriptions-transport-ws/node_modules/ws/lib/validation.js
9:28:52 AM: Module not found: Error: Can’t resolve ‘utf-8-validate’ in ‘/opt/build/repo/node_modules/subscriptions-transport-ws/node_modules/ws/lib’ @ …/node_modules/subscriptions-transport-ws/node_modules/ws/lib/validation.js
9:28:52 AM: @ …/node_modules/subscriptions-transport-ws/node_modules/ws/lib/receiver.js
9:28:52 AM: @ …/node_modules/subscriptions-transport-ws/node_modules/ws/index.js
9:28:52 AM: @ …/node_modules/subscriptions-transport-ws/dist/server.js
9:28:52 AM: @ …/node_modules/subscriptions-transport-ws/dist/index.js
9:28:52 AM: @ …/node_modules/postgraphile/build/postgraphile/http/subscriptions.js
9:28:52 AM: @ …/node_modules/postgraphile/build/postgraphile/index.js
9:28:52 AM: @ …/node_modules/postgraphile/build/index.js
9:28:52 AM: @ …/node_modules/postgraphile/index.js
9:28:52 AM: @ ./graphql.js
9:28:52 AM: WARNING in …/node_modules/ws/lib/validation.js
9:28:52 AM: Module not found: Error: Can’t resolve ‘utf-8-validate’ in ‘/opt/build/repo/node_modules/ws/lib’ @ …/node_modules/ws/lib/validation.js
9:28:52 AM: @ …/node_modules/ws/lib/receiver.js
9:28:52 AM: @ …/node_modules/ws/index.js
9:28:52 AM: @ …/node_modules/postgraphile/build/postgraphile/http/subscriptions.js
9:28:52 AM: @ …/node_modules/postgraphile/build/postgraphile/index.js
9:28:52 AM: @ …/node_modules/postgraphile/build/index.js
9:28:52 AM: @ …/node_modules/postgraphile/index.js
9:28:52 AM: @ ./graphql.js
9:29:25 AM: Error: connect ETIMEDOUT 54.215.126.234:5432
9:29:25 AM: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
9:29:25 AM: errno: ‘ETIMEDOUT’,
9:29:25 AM: code: ‘ETIMEDOUT’,
9:29:25 AM: syscall: ‘connect’,
9:29:25 AM: address: ‘54.215.126.234’,
9:29:25 AM: port: 5432
9:29:25 AM: }
9:29:25 AM: npm ERR! code ELIFECYCLE
9:29:25 AM: npm ERR! errno 1
9:29:25 AM: npm ERR! decoded-db@1.0.0 build: netlify-lambda build functions --config webpack.config.js && node src/makeCache.js
9:29:25 AM: npm ERR! Exit status 1
9:29:25 AM: npm ERR!
9:29:25 AM: npm ERR! Failed at the decoded-db@1.0.0 build script.
9:29:25 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
9:29:25 AM: npm ERR! A complete log of this run can be found in:
9:29:25 AM: npm ERR! /opt/buildhome/.npm/_logs/2021-03-12T17_29_25_458Z-debug.log
9:29:25 AM: ​
9:29:25 AM: ────────────────────────────────────────────────────────────────
9:29:25 AM: “build.command” failed
9:29:25 AM: ────────────────────────────────────────────────────────────────
9:29:25 AM: ​
9:29:25 AM: Error message
9:29:25 AM: Command failed with exit code 1: npm run build
9:29:25 AM: ​
9:29:25 AM: Error location
9:29:25 AM: In Build command from Netlify app:
9:29:25 AM: npm run build
9:29:25 AM: ​
9:29:25 AM: Resolved config
9:29:25 AM: build:
9:29:25 AM: command: npm run build
9:29:25 AM: commandOrigin: ui
9:29:25 AM: environment:
9:29:25 AM: - DATABASE_URL
9:29:25 AM: functions: /opt/build/repo/functions-build
9:29:25 AM: publish: /opt/build/repo/functions
9:29:25 AM: Caching artifacts
9:29:25 AM: Started saving node modules
9:29:25 AM: Finished saving node modules
9:29:25 AM: Started saving build plugins
9:29:25 AM: Finished saving build plugins
9:29:25 AM: Started saving yarn cache
9:29:25 AM: Finished saving yarn cache
9:29:25 AM: Started saving pip cache
9:29:25 AM: Finished saving pip cache
9:29:25 AM: Started saving emacs cask dependencies
9:29:25 AM: Finished saving emacs cask dependencies
9:29:25 AM: Started saving maven dependencies
9:29:25 AM: Finished saving maven dependencies
9:29:25 AM: Started saving boot dependencies
9:29:25 AM: Finished saving boot dependencies
9:29:25 AM: Started saving rust rustup cache
9:29:25 AM: Finished saving rust rustup cache
9:29:25 AM: Started saving go dependencies
9:29:25 AM: Finished saving go dependencies
9:29:25 AM: Build script success
9:29:38 AM: Finished processing build request in 1m18.068151195s

update: Trying to debug this and it seems that whatever machine the netlify build is running on simply can’t reach this endpoint.

For testing I added this package: is-port-reachable - npm

I added these lines in my build script just before the currently failing step:
console.log(‘google.com’,await isPortReachable(80, {host: ‘google.com’}));
console.log(‘aws rds’,await isPortReachable(5432, {host: ‘decoded-dev.ccds2q3g2i9m.us-west-1.rds.amazonaws.com’}));

When I run locally I get this:
google.com true
aws rds true

When the build runs in netlify it does this:
11:00:50 AM: google.com true
11:00:52 AM: aws rds false

update: Somehow in the default creation of a security group for an rds instance it created an inbound rule such that only my laptop could talk to it. I changed it to accept all on inbound and now it works.

1 Like

Hey there, @nimbus :wave:

Welcome to the Netlify Forums! Thank you for sharing your solution here, we appreciate it!