Can't access nestjs app deployed on AWS Amplify - nestjs

I've "successfully" deployed my nestjs app to AWS Amplify, but I can't access the endpoints. It's only returning 404 (as seen on the access log)
Do I need to make any changes to the source code or package.json for this?
You can see the deployed code here

Related

Node backend deployed to AWS S3 bucket - what is the end point URL for back end

I have a react app stored on an AWS S3 bucket and it seems to be working fine.
I have an RDS database that is up and running and I have the end point for it.
I have a node app that is running express and everything needed to take a request from the front end and "place" the data in the RDS database using that end point.
My question is - When the node app is deployed to the S3 bucket, what URL do I use in the front end to call the node app back end in the S3 bucket?
We have a similar setup at my work and the end point for calling the back end (S3 bucket with Node) from the front end is something like ...
https://xxxxxxxxx.execute-api.us-east-2.amazonaws.com/dev
https://xxxxxxxxx.execute-api.us-east-2.amazonaws.com/prod
I am not sure if I need to set up an api gateway or something to facilitate the routing of the call?
As mentioned in the comment, AWS s3 are for just static content. So you can only deploy a static websites on AWS s3 but not the nodejs app, as it will need node as a runtime.
If you want to replicate, then as mentioned its must be behind API gateway. so you need to understand the nderlying deployment resources which can be lambda, ecs or ec2. API gateway just route your traffic to the deployment.
AWS API Gateway
If you are just trying to run your backend with a few steps then AWS EC2 or AWS lightsail is the quicker option.
Ec2:
With EC2 you will need to configure and install each and everything for example nodejs runtime, npm etc
lightsail:
In lightsail you just need to select the node version and that's it.
Here are few docs that can help you to deploy your app using lightsale, lightsale instance come with nodejs version and does not need any installation, you just need to copy your code to the instance and start.
Once you able to deploy the app either on ec2 or lightsale, you just to copy the public IP from lightsale or ec2 and use that IP in the frontend app.
deploy-nodejs-app-in-aws-lightsail
amazon-lightsail-quick-start-guide-nodejs
deploy-node-js-server-on-aws-lightsail

Unable to call Elastic beanstalk APIs via amplify

I am new to AWS. I have my node/express.js backend hosted on the Elastic beanstalk and it's working as per expectation. The express.js APIs communicate with the AWS RDS MySql database and send response accordingly. I have integrated the APIs calls in the React frontend and it is working fine locally. Now I have deployed the React frontend on the amplify and React app is hosted there now. But the API calls to elastic beanstalk are failing on the Amplify with the response "TypeError: Failed to fetch". I have also analyzed the Elastic beanstalk logs but could not find anything there. I wanna know why API calls are working perfectly locally but not on the amplify?
I think the issue is that Elastic Beanstalk requires that the communnication protocol has to be the same for both sender and receiver. So, the solution is to use either HTTP or HTTPS for both Front-End and Back-End.

How do I fix UnknownEndpoint: Inaccessible host: `docker.for.mac.localhost' issue and connect to LocalStack from an Express server?

I am using LocalStack in a Docker Container to mock/host some AWS services locally e.g. SSM and DynamoDB. Using AWS CLI, these services are accessible on:-
docker.for.mac.localhost
I am using Express to debug a Lambda handler which fails to access these same services and gets the following types of error:-
ERROR: SSMError: Config could not be read from AWS Parameter Store{"data":{"name":"/ps/LOCAL/nationalGrid/metering/bmuAssetAttributeMap"}} --- UnknownEndpoint: Inaccessible host: `docker.for.mac.localhost'. This service may not be available in the `eu-west-1' region.
In the SSM and DynamoDB wrapper code the endpoint value is getting passed into the AWS SDK as:-
http://docker.for.mac.localhost:4566
However, it seems like, from a networking or DNS perspective, the Lambda that uses these services and is being triggered by Express does not have access to the mock LocalStack service running on this address in Docker.
Please can anyone advise on what might be the issue and how to resolve?
FYI We can trigger the Lambda using SAM Local correctly BUT we want the Webstorm IDE debugging capability which is why we are using Express.
Thanks!
Sam
UPDATE
In case it helps anyone else with this issue. For SAM Local the address for LocalStack endpoints in our setup needs to be:-
http://docker.for.mac.localhost:4566
But for Express it needs to be:-
http://localhost:4566

Execution flow of React + Node.js application deployed on AWS Cloudfront?

I am developing a web application in React with a Node.js back-end. I would like to host the images and static files built for the React application on Cloudfront. However, the React application relies on the Node.js server to obtain some changing data to populate the views.
I need to have a thorough understanding of the flow of the application in order to come up with a reasonable design. Here is what I think happens:
User enters URL in the browser
Client is directed to the closest Cloudfront edge location
Cloudfront serves the HTML and images to the browser
The React application bootstraps in the browser
An API call is made to the Node.js server, which returns the required data
The browser renders the React application.
Am I understanding this correctly? Is there a better way to architect my web application?
I am not able to find the information I require online and would appreciate any help!
Your architecture is correct.
Just to be clear, CloudFront is not hosting your files. CloudFront is a cache and will fetch your files from an Origin, typically an Amazon S3 bucket.
Using React && AWS Amplify, you can create a serverless architecture for this type of setup with minimal work. You can get started by following the instructions at https://aws-amplify.github.io/docs/
In a nutshel :
Install with:
npm install -g #aws-amplify/cli
$ amplify configure
Then in your project :
amplify init
amplify add api #this will create your API as AWS Lambda functions exposed through Amazon API Gateway)
amplify add hosting #this will create the Amazon S3 bucket for hosting and the cloudfront distribution)
amplify push #to create all this on your AWS account for you
If you search for 'aws amplify react' you will easily find a dozen blog posting showing you how to get started. There are so many I can not recommend one in particular.

Deploying react web application on AWS

I am looking to deploy my nodejs React web application on AWS. Currently I deployed my application on Microsoft's Azure and there is was pretty simple. I just had to add an App Service and give my git repository as the source to it. That took care of hosting my application. I am not getting a way like to do it on AWS. I am looking for something like that. How should I do it in AWS?
You can use AWS Elastic Beanstalk for this. Elastic Beanstalk is the PaaS offering which is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS. It is similar to Microsoft Azure App services.
You can simply upload your code and Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, auto-scaling to application health monitoring. At the same time, you retain full control over the AWS resources powering your application and can access the underlying resources at any time.
You can go through the tutorial for deploying your node.js app here- Deploying an Express Application to Elastic Beanstalk
One of the easy ways to do this in a Serverless manner is to use the new AWS Mobile CLI:
npm install -g awsmobile-cli
Then initialize and publish:
cd ./myproj
awsmobile init #answer some questions
awsmobile publish
This will setup an S3 bucket with CloudFront configured as your CDN to host your web assets. Your NodeJS app can be hosted in a Lambda function which is protected by API Gateway. A good way to configure the connection and authorzation from the client is to use AWS Amplify in your React application:
npm install aws-amplify --save
npm install aws-amplify-react --save
Then after doing an Amplify.configure(your_config_object you can connect to API gateway which calls your Lambda:
let apiName = 'MyApiName';
let path = '/path';
let myInit = { // OPTIONAL
headers: {} // OPTIONAL
}
API.get(apiName, path, myInit).then(response => {
// Add your code here
});
This will be a signed request to your AWS resources.
More here:
http://docs.aws.amazon.com/aws-mobile/latest/developerguide/web-getting-started.html

Resources