#✅ - Hosting ExpressJs API - Build Timeout

15 messages · Page 1 of 1 (latest)

viral nebula
#

I have an existing ExpressJs API that I want to host on Amplify. I will slowly migrate the endpoints to lambda functions, but for now I'm hoping to host the express API as-is.

The CI/CD is timing-out during the frontend provision/build step. I increased the build time to 120 minutes in "build settings". (Note: the UI won't save higher than 120 minutes)

Seems to be timing-out during package installation:

# Starting phase: preBuild 2023-08-25T13:52:20.450Z [INFO]: # Executing command: npm ci 2023-08-25T13:52:23.997Z [WARNING]: npm 2023-08-25T13:52:23.998Z [WARNING]: WARN deprecated [email protected]: Please update to at least constantinople 3.1.1 2023-08-25T13:52:24.056Z [WARNING]: npm 2023-08-25T13:52:24.057Z [WARNING]: WARN deprecated [email protected]: Deprecated, use jstransformer 2023-08-25T13:52:24.311Z [WARNING]: npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade 2023-08-25T13:52:29.147Z [INFO]: added 218 packages, and audited 219 packages in 8s

Has anyone experienced build timeout issues?

Thanks in advance!

#

Hosting ExpressJs API - Build Timeout

signal mica
#

Hey 👋 for what it's worth you can run the entire Express app in a single Lambda, but out of curiosity do you have a frontend attached to your Amplify project?

viral nebula
#

Ohhhh... I didn't think of running the entire app in a single lambda.

No frontend is attached.
The ExpressJS framework has its on templating system for views. I was thinking that would be the frontend setup during 'npm run start'

#

If I can put it into a single lambda, It may be easier to make a blank frontend, create a backend with a Lambda and toss everything in there

signal mica
#

ahhh that must be why the frontend step is timing out. What does your amplify.yml look like?

#

The ExpressJS framework has its on templating system for views.
this makes sense after seeing pug & jade in the log output.

You can use this package to run an express app in a Lambda https://github.com/vendia/serverless-express
Then you might be able to set up a rewrite rule in Amplify Hosting to point to your API Gateway endpoint where your express app lives

GitHub

Run Node.js web applications and APIs using existing application frameworks on AWS #serverless technologies such as Lambda, API Gateway, Lambda@Edge, and ALB. - GitHub - vendia/serverless-express: ...

viral nebula
#

As I was typing it, I realized that might be the cause...

Here is my amplify.yml:

version: 1 frontend: phases: preBuild: commands: - npm ci commands build: commands: [npm run start] artifacts: output directory baseDirectory: / files: - '**/*' cache: paths: - node_modules/**/*

Package.json 'start' command seen below:

{ "name": "server", "version": "0.0.0", "private": true, "scripts": { "start": "node ./bin/www", "dev": "nodemon ./bin/www" }, "dependencies": { "concurrently": "^7.6.0", "cookie-parser": "~1.4.4", "cors": "^2.8.5", "debug": "~2.6.9", "express": "~4.16.1", "http-errors": "~1.6.3", "jade": "~1.11.0", "jsonwebtoken": "^9.0.0", "mongodb": "^5.7.0", "morgan": "~1.9.1", "multer": "^1.4.5-lts.1", "nodemon": "^2.0.20", "pg-promise": "^11.3.0" } }

#

You can use this package to run an express app in a Lambda https://github.com/vendia/serverless-express
Then you might be able to set up a rewrite rule in Amplify Hosting to point to your API Gateway endpoint where your express app lives

Thanks for the resource. I'm going to look into this now 👍

signal mica
# viral nebula As I was typing it, I realized that might be the cause... Here is my amplify.y...

ah, yes. the build system in Amplify Hosting will not be able to run the express server. you can likely swap the frontend build command to a simple echo, then use rewrite rules to point to the API gateway endpoint https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#reverse-proxy-rewrite

#

and if you run amplify add function there is an option for serverless Express if you'd like a boilerplate 🙂

viral nebula
#

Perfect. Thanks so much for taking the time for this. Exactly what I need! amplify 😄

signal mica
#

absolutely! glad to have helped! let us know how it goes!

hot ospreyBOT
#

✅ - Hosting ExpressJs API - Build Timeout