how can I use cloudfront with multiple beanstalk environments? - amazon-web-services

right now I have an app that runs on several beanstalk environments in different regions and use route53 geo location records for routing
I want to use cloudfront for these environments
Can I create a cloudfront for each environment and route to them with route53? Or can I create a single cloudfront and connect all of the beanstalks to it? Do I have to use cloudfront lambda to do something like this?

Can I create a cloudfront for each environment and route to them with route53?
CloudFront and Route53 don't relate to each other.
Route53 gives URL of an application (deployed to Beanstalk in this case) to end users. When users open this URL, they will see something rendered. This something uses resources. These resources can be stored in CloudFront CDN or can be stored in your application.
You can see that Route53 doesn't collaborate with CloudFront here.

Related

How to use cloudfront for path based routing between ec2 and amplify with the same domain name?

I have an API on a AWS ec2 instance with the route domain.com/api. And I have deployed a NextJS app on amplify which I want to show on the home page of my domain.com. How to use cloudfront to distinguish between the two and send resources accordingly?
I have managed to set up CloudFront but it is throwing an access denied error. I have set up a load balancer for my EC2 instance also. What might be wrong here?
The API on ec2 and the app on amplify is working independently. I have checked them both.

How to deploy a website and webservice in AWS using same domain name

We have to deploy Restful Webservice(API services) and static pages in the AWS environment.
Currently, our Webservice is hosted in EC2 instance with one ELB and Route53. Also, the static pages are deployed in the S3 bucket. The Webservice and Website, both should be in the same domain.
When the user calls "www.domain.com/" it should be routed to the S3 server. However the API calls (www.domain.com/api/**) should be routed to EC2 through ELB. Is there any way to
route API calls to ELB and website access calls to S3 using Route53?
or What is the best approach to resolve this?
Yes, you can deploy both using the same domain name. APIs should be deployed using api.domain.com and websites can deploy using domain.com. For that, you need to purchase an SSL certificate with a domain name and subdomain (eg: https://example.com and https://api.example.com) support and do the following.
Configure certificate in AWS ACM
Deploy your website in the S3 bucket with CloudFront
Deploy APIs in EC2 with the support of a Load balancer (ELB)
Configure Route53 and define two routes. Ie, create Records with 'A record type' in Route53 with ELB address and CloudFront address.
See sample deployment architecture

AWS replace EC2 with CloudFront

I have a domain dev-www.myexample.de hosted via AWS EC2 and a Load Balancer. I want to replace this configuration with an S3 bucket + CloudFront and keep same domain name.
The only possible way I could find was destroying my EC2 instance and Route 53 and then deploy my CloudFront and domain and this works fine.
However, I want to show a 503 page for all traffic that comes while my EC2 instance is down and before my CloudFront and S3 bucket are ready to use. Any idea how I can do that?
You can create your Amazon S3 bucket and Amazon CloudFront distribution before changing the DNS configuration. This gives you an opportunity to ensure that it is working correctly.
Then, you can change the Route 53 configuration to point to CloudFront instead of the Load Balancer. It will take some time for this change to propagate throughout the Internet, during which cached queries will continue to go to the Load Balancer but new DNS lookups will go to CloudFront. If you have the same content in both locations, there should not be a need to display any notice.
Please note that only static content can be served from Amazon S3, so if you had any back-end logic in your Amazon EC2 servers, it would not be possible to continue providing it with CloudFront + S3.

AWS - Hosting Elastic Beanstalk + S3 behind ELB

I have an Elastic Beanstalk instance serving a backend app running natively HTTP and an Angular app hosted on a S3 instance.
Now, I would like to put these on a single domain www.example.com, behind a SSL protected Load Balancer which will route the request internally by the URI, either to the backend (/api/) or angular app (/). For this I setup a Route53 DNS which I wired to the LB.
I don't see an option to route directly from LB to the S3 instance though. I've read that, I should create a CloudFront distribution for the angular app and specify the LB as the origin but after configuring CF distro, I don't see any option inside of the LB to connect it to the angular app. How should I approach it?
Routing should be handled on CloudFront not on load balancer in this case. You can create multiple behaviors in CloudFront, each pointing to a different origin. So you can choose default CloudFront behavior(*) to point to your s3 bucket and create second behavior that is used whenever URL contains /api to point to your load balancer origin.

How to config two different applications in different EC2 instances under the same domain in Route53?

I'm setting up new two servers in different EC2 instances, and want to run two different applications, one on each EC2 instance:
3.14.23.108:8080/clients
18.23.34.23:8080/products
I need that those endpoints run under the same domain Route53:
www.mydomain.com
And I expect some like this:
www.mydomian.com/clients
www.mydomian.com/products
I know some services of AWS like ELB, Api Gateway, and CloudFront but don't find a good example or tutorial por that.
You can use API Gateway with proxies to specific EC2 instances. See https://aws.amazon.com/blogs/aws/api-gateway-update-new-features-simplify-api-development/ in the bottom search for "Use HTTP Proxy integration" and specify HTTP. Then set Route53 alias to the API Gateway.
You can setup AWS application load balancer with path base routing .
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/tutorial-load-balancer-routing.html