Angular Universal - Deploying to AWS Elastic Beanstalk - node.js

I have been trying and failing for over three days now to get this working, and am growing increasingly frustrated with my own lack of understanding on the topic - so this is my search for an answer that I've not yet found.
I am using Angular 9.x and Angular Universal 9.x and am unable to work out how to deploy this to Elastic Beanstalk on a server running node. There are zero tutorials that explain how this should be done, as they are all aimed at those wanting to use Lambda on AWS. If someone could please point me in the right direction that would be great. I run npm run build:ssr --prod, and get the following in my dist folder:
[
I have tried deploying this folder by uploading it zipped, as well as tried eb deploy with my whole app - but all of these result in errors like the following (for eb deploy method)
> blush-front-end#0.0.0 start /var/app/current
> ng serve
sh: ng: command not found
Could someone please point me in the correct direction?

I struggled for months too because of the lack of tutorials online on how to deploy Angular Universal to AWS Elastic Beanstalk. And you will now be very happy to know how easy it is.
First, run the command npm run build:ssr to build for production.
Inside the dist folder, you will probably find a folder with your project name. Inside this folder you will find a "browser" folder and a "server" folder. Inside the "server" folder it is the main.js file.
Your setup might be slightly different, but you will be able to adjust this explanation to your situation after you read my entire answer.
Zip the dist folder.
Let's now configure the environment in AWS Elastic Beanstalk.
1) When you create an environment in Elastic Beanstalk, choose "Web server environment", and then on Platform branch config, choose the last option: "Node.js running on 64bit Amazon Linux". This is a very important step, since this is the only option that will enable you to configure the Container Options.
2) On the Application code, choose "Upload your code" and upload your zip file.
3) Click on Configure more options
4) Click on the Edit button on the Software box.
5) On the Node command field,type node dist/yourProjectFolderName/server/main.js
That's it!! Save and create your environment. Your app will work now. :-)

Related

index.html not found while deploying MERN app to render.com

I was trying to deploy my MERN based E-commerce website on render.com, after the render terminal shows the build was successful the the webpage shows the error as,
{“message”:“ENOENT: no such file or directory, stat ‘/opt/render/project/src/frontend/build/index.html’”,“stack”:null}
I’m a complete beginner to render and MERN too,
I have no bulid folder in my local
then I tried to create another test app by npx create-react-app test to check if build folder is actually present in there or not, But it is not there, I’m totally in Confused now…
I’m Giving my repo here → stunning spark
I just want to have clear answers for my questions(Please!!!)
Things I want to change in my directory to deploy and host my app Successfully.
Things Need to be configured in the render’s settings
Thanks in Advance!!!
I just want to deploy and host my application on render.com
Just run npm run build into your frontend folder and do check you have removed the "build" keyword from the .gitignore file because it won't let you push the build folder to GitHub and you are good to go.

"You didn't include a 'package.json' file in your source bundle..." while the file is there ? Beanstalk

So we have 3 environments on this project and our dev and stg environment deployments work fine, but when I created a Beanstalk and went through the "eb init" and changing the gitab-ci.yml file I get the Instance deployment: You didn't include a 'package.json' file in your source bundle. The deployment didn't install a specific Node.js version. error and I just don't know what it wants from me. I hit ls on the runner commands and it obviously shows the package.json file in the root and it contains the defined Node version + it's exactly the same for dev and stg :O
All the envs are the same Node version, they all have the same setup, but for some reason it won't deploy to prod. Best thing about it is when I manually zip all the files and upload it via the console it all works fine so I don't know what to do. Any advice? Thanks in advance :)

showing Failed to find package.json. Node.js may have issues starting. Verify package.json is valid or place code in a file named server.js or app.js

showing Failed to find package.json. Node.js may have issues starting. Verify package.json is valid or place code in a file named server.js or app.js. when deploying node js file in AWS ELASTIC BEANSTALK cloud, what are the reasons to showing that message and how to resolve that issue.
There can be multiple reasons. Can you please check the logs generated in Beanstalk.
The way how you have zipped the package can cause an error. Make sure, you go inside the source directory and zip the files and folders, instead of zipping the single folder itself.
Secondly, the way how you have created the app.js or index.js.
The Nodejs versions can be another reason.
The below approach worked for me 2 years back when I started using Beanstalk for my Nodejs applications.
Also, I would recommend deploying a sample nodejs application from this link and progressing from there. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-getstarted.html

Deploy only the build artifacts of a Next.js project

I'm trying to deploy a Next.js project using a Docker image and I was wondering if it's possible to simply use an already generated dist folder (.next) and start the next.js server (npm run start) without having to trigger the build step again in the container.
The container will be hosted in AWS Elastic Beanstalk and I also want to avoid uploading the source code and installing the npm packages there, as I already have a CI pipeline that is generating the production artifacts.
Answering because I was going through issues with this myself and found this question. My research shows the only way to accomplish this is to run a docker environment on beanstalk and not node.js. The primary reason is that there are absolute paths in the .next build artifacts so you have to build on each instance and you have to make sure that BUILD_ID is synced across those instances.
If you CI pipeline can handle creating and pushing the Docker image, then its pretty easy to deploy on Beanstalk without any rebuilding etc. Hope that helps!

deploy to google cloud platform flex env does not include directories?

AFAIK when using the google cloud sdk shell to deploy to the google cloud platform flex environment the deploy does not include the directories. For example, I'm following this nodejs express tutorial - https://cloud.google.com/nodejs/resources/frameworks/express. I can run the app locally. I deploy using gcloud app deploy running it in the same directory as app.yaml. However, after the deployment I get an application startup error:
node ./bin/www:
module.js:471`
throw err;
Error: Cannot find module '/app/bin/www'
I am able to deploy and run the hello world nodejs tutorial app, but that app has no sub-directories. However, if I modify that app to use EJS and put .ejs files in a 'views' folder and then deploy, the deploy works but the views folder is missing! I've verified that it is missing by using 'fs' in app.js to print out the files and directories of the current folder and guess what - NO directories except the node_modules folder which gets created during the deployment.
I've also tried deploying a python flask app that seems to have the same error (basically it cannot find a template because the templates folder does not exist...).
Has anyone else experienced this? Do I need to do something special in the deploy? I'm very surprised that not even Google's own sample tutorial app does not deploy.
Thanks!
I spent my whole day on the same issue. It looks like it was a problem with the new gcloud sdk shell. You can downgrade your version by 'gcloud components update --version=137.0.1'
It workes for me

Resources