Using comparative logic in AWS DNS/Route 53 records - amazon-web-services

We have a site setup in AWS. When we bring up a stack for a new release we make it available at a versioned URL. i.e.
V1 available at v1.mysite.com
V2 available at v2.mysite.com
etc
Is it possible to make a single DNS entry that will point to the latest deployed version of my site automatically? So, after I deploy V1, I would have two DNS entries:
v1.mysite.com which goes to the IP of it's stack
mysite.com which redirect to v1.mysite.com
Then when I deploy V2, mysite.com now redirects to v2.mysite.com without me manually having to edit the DNS entry.
In general, can I automatically make DNS entries or make some kind of wildcarded DNS entry that will always point to the highest numbered version of my site currently available in AWS? It should look at the digits after the V for all currently available DNS entries/stacks and make mysite.com point to the numerically highest one.
We are using CloudFormation to create our stacks and our DNS (Route 53) entries, so putting any logic in those scripts would work as well.

This isn't part of DNS itself, so it's unlikely to be supported by anything on Route53. Your best bet is a script that runs when your new instance starts or is promoted to be the production instance. It's pretty simple using boto:
Create a new boto.route53.record.Record
Create a new boto.route53.record.ResourceRecordSets
Add a change record with the action UPSERT and your record
Commit the ResourceRecordSets (with a simple retry in case it fails)
get_change() until Route53 replies INSYNC
Depending on your application you may also want to wait for all the authoritative DNS servers (dns.resolver.query('your-domain', 'NS')) at Amazon to know about your change.

We ended up must making this a manual step before deploying a new stack. If the new stack needed to be resovled at mysite.com, the deployer has to manually remove the existing mapping. Then the cloud formation scripts will create the new DNS mapping.
Not ideal but better than a ton of messy logic in cloud formation scripts I suppose.

Related

2 AWS Lightsail instances what happens when one gets changed

lets say you have a big Website so you need to add a additional instance of a AWS Lightsail server. So you do a Snapshot and create a new Instance. The instance hosts Plesk on Ubuntu and has a database and a WordPress site.
Now somebody registers on the website and the created user gets added to the database. Does the user now also get added to the additional instance? If not how can you add the functionality that when a edit happens on one instance the other Instance also overtakes the changes.
I'm just getting started with AWS and would like to find out.
If a user registers on Server 1, it would not reflect on Server 2. Similarly, any posts made on the first site would not show up on the second site. This is because the disk (which holds both the database and any files necessary for posts) is not shared between the two instances, so any changes made to one disk are only reflected on that one server.
Honestly, for hosting Wordpress, your best bet is probably to use a dedicated Wordpress host so you don't need to worry about scaling.
However, you can do what you're looking to do in AWS as well. You essentially need a shared database, which you can do either with a third instances or by using Amazon's RDS service. If you have enough load that you need more than one server, I'd highly suggest using AWS's RDS service instead of trying to build your own database service. Once you have a shared database, posts and users registered in one server will show up on the other. You'll also likely want a load balancer to balance requests between the two servers (there is a service called "Lightsail Load Balancer" that's meant for this).
If you're dealing with a significant request load, you should take a look at AWS's reference architecture for WordPress: https://docs.aws.amazon.com/whitepapers/latest/best-practices-wordpress/reference-architecture.html
Happy Reading!

How to migrate from one cloudfront distribution to another

We're using cloudfront to front end a web app (myapp.com with s3, lambda, athena, ... etc)
Before a new release we're creating an entire new distribution (next.myapp.com) with new code and content, testing and then would like to make it the live version of myapp.com. But this doesn't seem possible.
Multiple Cloudfront distributions can't have the same CNAMEs so we can't change the DNS entry for myapp.com to point to the new service.
Changing the distribution means there's a delay as the new config populates around the world.
Is there away of doing this using amazon infrastructure? Or am I doing this completely wrong? Would like to be able to migrate the live service ASAP, but still have the existing version available for manual failback if the release breaks something
This is possible with only a very brief period of downtime, if you follow these steps.
Create the new distribution with the correct certificate but no Alternate Domain Name, and allow it to stabilize.
Change the DNS for the site to point to the new distribution. This does not have the negative impact that you would assume, because the site continues to work on the existing distribution. CloudFront does not differentiate between arrival endpoints -- it's only looking at the SNI and Host header, matching these against the Alternate Domain Name -- so the old distribution will continue to handle the traffic.
Edit the existing distribution to remove the Alternate Domain Name. You do not need to wait for it to return to "Deployed" status.
Edit the new distribution to add the Alternate Domain Name. You may have to attempt this more than once but it will eventually be accepted.
The trick is to use *.myapp.com as CNAME for the new distribution, switch your DNS records to point to the new distribution and when the switch is effective you clean everything up.
See Moving an Alternate Domain Name to a Different CloudFront Distribution.
It's not possible to do this for a second-level domain (myapp.com) without contacting AWS. The solution is to use www.myapp.com for the live version and have another distribution only for the HTTPS redirection from myapp.com to www.myapp.com (or a redirection with S3 but HTTP only then). The CNAME for this distribution would never need to be updated.

Create Google Cloud Virtual Machine from PHP

I'm new in cloud environment (Google Cloud)..
Currently I have more than 10 different products of php application software.
I have website where users can register and create their own subdomain name...
Every time users register on my website, I create the VM manually and point the subdomain to the VM manually...
When users registering on my website is increasing, it become very hard to manually add the VM and point the DNS one-by-one
What in my mind is can we automate the process? if possible how to do that?
What is the best method for this?I heard about container and kubernetes...
all information, help and suggestion is appreciated...thank you
you can use code as infrastructure like terraform is there.
you can run terraform php.
Refer more about it here : https://github.com/aol/terraform-php
Where you can set everything and it will also spin up VM behalf of you known as code as infra.

How to setup maintenance page in AWS without modifying Cloudfront?

We will be deploying changes in our production environment and would like to put up a maintenance page during the deployment. No redirection to error page but simply display the maintenance page when they hit our website. Our current production setup is, DNS->cloudfront->S3 object (mydomain.test.com). Our staging is, DNS->R53->Cloudfront->S3 (mydomain.staging.test.com->mydomain.staging.test53.com). I would like to test this first in our Staging env so that if it works, I will have the DNS entry of our prod env modified and pointed to a new R53 I will create.
What I've done so far is, create an S3 bucket that has the maintenance.html object, created a Cloudfront and R53 solely for the maintenance page. Added the S3 object as the default root object in the CF and mydomain.staging.maintenance.test53.com as alias. Also added the CF as the cname in the R53. So when I load the r53 mydomain.staging.maintenance.test53.com I see the maintenance page.
However, for this to work I have to update the CF of our live environment to remove mydomain.staging.test.com and mydomain.staging.test53.com and add mydomain.staging.maintenance.test53.com as alias then update the staging live R53 to point to the maintenace R53. This works but the CF changes takes time to propagate.
Would appreciate any suggestions!

Assign domain name through CLI - AWS [duplicate]

I have got a domain registered with GoDaddy and an EC2 instance with public elastic IP and I'm trying to use Amazon "Route 53" service to map the DNS name to my instance.
In online documentation there is a very complex example of using Perl (http://aws.amazon.com/code/Amazon-Route-53?browse=1) to achieve this result.
Is there a simpler way of doing this?
The AWS team has meanwhile added complete support for Amazon Route 53 to the AWS Management Console as of November 16, 2011, which allows you to create your hosted zones and set up the appropriate records (A, CNAME, MX, and so forth) in a convenient visual environment.
This is best experienced by exploring it yourself of course, but a sneak peak is available via Amazon Route 53 and the introductory blog post AWS Management Console Now Supports Amazon Route 53 provides a walk through the entire process of registering a domain at a registrar and setting it up in Route 53, including further illustrations.
Currently there's no "Route 53" tab on AWS management console. But they've said that they'd be adding one in the future.
http://aws.typepad.com/aws/2010/12/amazon-route-53-the-aws-domain-name-service.html
So right now, the easiest way is to use third-party tools. Here's a list of tools that you can use:
http://aws.amazon.com/developertools/Amazon-Route-53/
http://aws.typepad.com/aws/2011/02/new-location-for-route-53-and-cloudfront-route-53-tool-roundup.html
https://github.com/rawswift/aws-sdk-for-php
I've also built a web-based interface for AWS Route 53. Has the basic features like creating/deleting hosted zones, adding/deleting A, AAAA, CNAME, PTR, SPF, SRV, TXT records and also supports multiple MX record value (e.g. Google MX records).
https://nsroute.com/
Thanks
I've been pretty pleased using Interstate53:
https://www.interstate53.com/
It offers a nice GUI for managing all of your Route 53 configuration.
There are several web GUIs available for creating and modifying Route 53 zones and records including https://www.interstate53.com/
More options are listed in the documentation at http://docs.amazonwebservices.com/Route53/latest/GettingStartedGuide/
Hope these links help you setup:
http://dmz.us/2010/12/amazon-route-53-dns/
Using Boto library:
http://agiletesting.blogspot.com/2011/06/managing-amazon-route-53-dns-with-boto.html
This link, gives you a straight forward flow of configuring DNS to EC2 instance:
http://support.rightscale.com/03-Tutorials/02-AWS/02-Website_Edition/2._Deployment_Setup/4._Domain_Setup/Domain_Setup_with_Amazon's_Route_53