How do I host a Node.js server on AWS cloudfront? I'm trying to make a social media - node.js

I am using AWS cloudfront to store data but I need a backend (Node.js) server to upload and delete data automatically. How can I connect a node.js server to AWS cloudfront, with access to read and write its files?

AWS CloudFront acts as a CDN (Cache and a Proxy) and you can put it in front of your Node Server. You can connect your NodeJS server (DNS) as an origin and provide caching rules as behaviors (e.g; /js/* /api/* ).

Related

How do I fix the Error when setup AWS Application Load Balancer For Angular+NodeJS Web Application

I set up an Application Load Balancer(AWS) for my website. In my website, I have angular as my frontend, and I have NodeJs and Neptune DB as my backend.
Browser(Local Machine) -> ALB -> EC2 Instance(Web).
I have an url for my web(https://example.com), so when I made a request to https://example.com in my local machine browser, Angular will do a api call using httpclient.get() to fetch data from nodejs at https://example.com/api/ticket.
So my question is when Angular fetch data from NodeJS, will the api call bypass the ALB, what is the host then? Or NodeJs will recognize the request is from the local?
I assume you are using an ALB with Host based routing. In this case you can have a 443 rule for example.com forwarding requests to the EC2 instance. Then in the Nodejs application you can have that api called using the same url.
This means that the request will be routed through the ALB which is also the best practise to do the same.

How to deploy Node.js Express server + Vue.js app on AWS EC2

I'm setting up my website which would run on an AWS Ubuntu EC2. It is a Vue.js SPA relying on a Nodejs Express app with API calls and socket.io. So far both apps are working, the backend is on my AWS EC2 free tier, behind an Elastic Load Balancer, the frontend is on my machine since I working on it. Now I would like to deploy the frontend to my AWS EC2 also but I'm confused how to do it correctly. The tutorials I've found are using nginx but I'm not sure that I need nginx as I already have AWS ELB. Any advices would be great :)
as is says "If you are developing your frontend app separately from your backend - i.e. your backend exposes an API for your frontend to talk to, then your frontend is essentially a purely static app" here
I would choose s3 to host vue app because it's static and can be served using s3 and
I will choose EC2 for hosting my API (server code) and also i'd make an elastic IP to talk to my ec2 server so that on restart i don't have to handle the dynamic IP's
Steps to make your website live
First pull yout node express server on your ec2 instance
start your node express server use pm2 to serve it as an service
expose the served port from security groups of the ec2 instance
make an s3 bucket on aws and upload files to it
Tip: just click upload button after dropping your files to s3 do not go clicking next
after uploading select all the uploaded files and then mark as public
after uploading go to properties of that bucket and then choose static web hosting and type index.html the asked field
** TIP: do not use a load balancer for this application use only when you distribute your system across multiple ec2's**

Project in S3 bucket doesn't connect to node server in EC2 instance

AWS newbie here. I have a web app where the Angular dist package is hosted in an S3 bucket, and the backend is being served on an EC2 instance. I've been following this tutorial, but after completion my project in the S3 bucket still does not connect to my remote node server.
What I understood from that tutorial was that by setting up a CloudFront distribution, it will connect the S3 bucket with the EC2 instance. But if I navigate to the CloudFront domain, it loads the S3 bucket contents but still does not connect to my node server.
When I run the node server locally, it connects successfully and I'm able to read and write to my remote Mongo database. This indicates that:
1) the connection to the remote MongoDB is successful, and
2) the front end (in the S3 bucket) is looking for a local node server instead of the remote one (in the EC2 bucket).
So my question is how do I make it so that my services make calls to the remote server instead?
Firstly S3 only hosts static content. So all your Angular dist files will sit on S3. S3 does not connect to your backend. Your browser will try to make AJAX rest calls to your Node Server.
Second your backend Node server needs to expose its Rest services via an API gateway. Thats the recommended approach. It seems if your app is trying to connect locally because of config error. You need to use the API gateway link in your Angular app.
For a quick test you could expose the port in the Security Group of your EC2 and use the public IP of your EC2 to access the node app before going about setting up API gateway.

Access AWS Node SDK inside firewall without changing any configuration in firewall

I have a desktop app which downloads app assets after installation is completed.
App uses aws node sdk to download all the assets from S3 buckets.
Problem comes when app is getting installed inside company firewall. Company firewall blocks the api request used by aws node sdk.
And I can't ask all my client to white-list amazon web service urls but I can ask them to white-list my own company url like *.mycompany.com.
Is there any way we can access aws node sdk using my company domain.
We had this same problem and resolved it by creating a proxy API endpoint on a separate server that would take the request, and pipe the stream from AWS S3 back to the client. Because this proxy endpoint was hosted in a whitelisted domain, we didn't have to worry about the company's firewall blocking the request.

HTTPS requirements - express server on AWS elastic beanstalk

I have written an express application which I have deployed on AWS. I want to understand if I need to enable https in my node js express server code or if the https enabled in the AWS console is enough i.e. is https between the web client and the AWS load balancer enough to protect my site or do i need to enable https within AWS infrastructure internally as well. Are there any other security considerations to be aware of in this scenario?

Resources