Is AWS Amplify only cares about the serverless backend or can I connect my REST API to it?

I am having my SPA website created using Reactjs. The website internally calls REST API which fetches data from AWS RDS MySQL. The REST API is build using Java and deployed on an ec2 instance behind the Apache server.

The Reactjs is using Amplify for deployment. How do I structure my AWS so that the Reactjs using REST API on ec2?

Amplify has automated backend provisioning with AppSync, API Gateway and DynamoDB which makes live easier to have several environments (Dev, Test, Prod) with separated data stores.

But this does not mean that you have to use all of it. You can simply use Amplify Console to host your front-end files. Amplify Console hosts you files over CDN network and provides such features as custom domains and redirect rules.

As for back-end, you can provision your own back-end infrastructure and do REST HTTP calls from the React application. Here is one of the articles on how to consume REST APIs: https://pusher.com/tutorials/consume-restful-api-react

From hosting perspective you have multiple options for EC2-powered backend:

  • Just have stand-alone EC2 instance with Public IP in a public subnet. You can create a Route53 public zone with your custom domain and create A record pointing to the public IP of the EC2 instance. But if something goes wrong with the instance hardware or application configuration you will lose your backend services entirely. This option should not be used for production workloads.
  • Create public Application Load Balancer (ALB) to have single public endpoint. Create a Route53 public zone with your custom domain and create CNAME Alias record pointing to the ALB created in the previous step. ALB can work directly with your EC2 instance as a target or you can create Auto-Scaling Group (ASG) which can provision more instances of your back-end when you have more traffic and scale it down when you have less traffic. ASG can also can work as a “self-healing” mechanism if underlaying AWS hardware fail - it will provision a new EC2 instance. More information about auto-scaling can be found here: https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html Additional features of ALB described in this document: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html
  • Create API Gateway, configure Route53 to support custom domain. And then you can use ALB and ELB as in previous example. This is a more complex solution and probably makes sense to use it if you want to plug in some other services on the top, for example have Cognito authorisation and authentication for your backend services, or provide request throttling and so on.More information about it here: https://aws.amazon.com/blogs/architecture/using-api-gateway-as-a-single-entry-point-for-web-applications-and-api-microservices/

So depending on the type of your application you can pick right solution for you. If you are just developing your application and availability and scaling is not a priority for you - go with option 1, if this is a production solution and you consider using auto-scaling - option 2 is a good choice.

In case you would like to try out serverless approach and use AWS Lambda in both options 2 and 3 you can route some of the requests to Lambda and the rest to continue to be sent to EC2 instance(s).

Also do not forget about pricing - each load balancer by itself will increase your monthly spend by 16-17$ + traffic/requests costs. If you use autoscaling - each additional instance will multiply EC2 instance price by the number of instances.

My application knows how to talk to the REST API and even I have deployed both Reactjs and REST on a single ec2 instance and everything is working fine. But that was just to test AWS. My setup: I installed Apache onto the ec2 and set reverse proxy to handles the incoming requests. All the requests to “www.mydomain.com” were going to the Reactjs application and all the “www.mydomain.com/api” were going to REST service. The Reactjs application was making CRUD requests to “www.mydomain.com/api”.

I will test your approaches and will posts the results here. Thanks for your time :slightly_smiling_face:

So, I tried understanding your approaches to the problem, but you nowhere mentioned the frontend application(Reactjs) deployment. Plz include that as well.

You can simply use Amplify Console to host your front-end files. Amplify Console hosts you files over CDN network and provides such features as custom domains and redirect rules.

I have updated my answer, basically you can continue using Amplify for front-end hosting, just without its additional features.