Amazon Web Service (EC2)

  • Amazon web service provide tons of cloud computing related services, and EC2 is one of the general cloud computing service, which basically let you to create a virtual machine online and do anything about it, while one most popular user case is to use it as online hosting server, providing webpage, database, email, and dns services.
  • EC2 (Elastic compute cloud)
    • it allow you to create a virtual machine with specification on demand at any time with a unique IP address.
  • Amazon Machine Image (AMI)
    • as EC2 allow to create a virtual machine, a virtual machine needs a operating system to run, Amazon provide with various options of major linux servers and windows server image file to clone into your virtual machine
    • these OS image is called AMI, and they are pre-configured from default installation, so you don't need to install fresh like tradition desktop OS install.

Amazon Linux for your new instance

Default Spec Sheet

ec2-user default user name
need the key pass
22 ssh port

Common Post-Install Application Spec Sheet

/var/www/html Apache html root
/etc/httpd/conf/httpd.conf Apache server config
sudo service httpd restart Apache server restart command
  • ssh to ec-2 linux from local
    • first, make sure your key file is protected
      chmod 400 /path/my-key-pair.pem
    • then, run ssh
      ssh -i /path/my-key-pair.pem ec2-user@your_domain_or_free_amazonaws.com
    • cd to your website
      cd /var/www/html

other free pre-config Linux in AWS Marketplace for your new instance

  • if you tried the blank Amazon linux, you may feel the pain to install each service by yourself.
  • that is why there is more pre-config Linux options in AWS Marketplace tab than Quick Start tab
    • in which, there are pre-config and software loaded Linux virtual machines, which are ready to use once loaded into your new instance, like wordpress with all those servers, dokuwiki with all those servers.

Note

Basic
AMI username bitnami
htdoc location: /opt/bitnami/apps/wordpress/htdocs
http.conf /opt/bitnami/apache2/conf/httpd.conf
ftp your_domain.com; user: bitnami; port 22; with key installed in ftp client
Advanced
ssh
ssh -i /path_to_the_key.pem bitnami@your_domain.com
restart apahce
sudo /opt/bitnami/ctlscript.sh restart apache
  • tip:
    • quit ssh by: exit

Backup and New EC2 Instance

  • situation:
    • sometimes, the instance stuck up with a snapshot image, or bad overall server config setup,
    • rather than fixing existing ec2 instance, you may just want to bring down everything and start a new one, here are the steps

Backup important file list in current instance

  1. backup web root (for Amazon AMI, it is under /var/www/html)
  2. backup http.conf (for Amazon AMI, it is under /etc/httpd/conf/httpd.conf)
  3. backup database if you have

Shut down current instance

  1. go Instances tab, action on selected instance
    • stop Instance
    • terminate Instance with volume deletion (it will be auto deleted after 20min)
  2. go Image tab:
    • AMIs: deregister all images (other customized image from your instance created)
    • deregister take about 5 min for it to be gone
  3. go EBS tab:
    • volumes: it should be gone with the instance
    • snapshots: delete all (if not successful, make sure you deregister the AMI associated with it in above step)

Start new instance fresh

  1. Instance tab
    1. launch (create) new instance (here is example of wordpress one)
    2. in the disk image list, go AMS Marketplace: search wordpress, choose “Wordpress by bitnami” (not multisite one)
      • note: this image is based on ubuntu 16.04, and software cost 0 (free), aws instance use still cost like other intance standard charge.
      • note, dokuwiki pre-install ubuntu AMI also available free by bitnami (https://bitnami.com/aws)
      • basically, you don't need to start from a blank scratch Amazon AMI disk image, and setup LAMP and every bit yourself.
      • just continue, with Wordpress
      • choose Instance type (power charge based on instance performance), for free iter, only t1.micro (1cpu,0.6G ram) and t2.micro (1cpu, 1g ram) (t2 > t1)
        • t2.micro (free tier), Next: Configure Instance Details.
    3. configure, leave as default, click “Add Storage”, default 10 gb at least since the wordpress disk image is = 10gb, you can use bigger if you want but not smaller, (free tier can use for 30gb, but after that, 0.12 sgd per GB per month), click Tag instance
    4. tag instance: “Name”:“MyWordPress”, review and Launch
    5. in review page, it show instance spec, and auto security group created by the image template, just click Launch
    6. the key page poped, for download ssh key for the OS (if you have a key before during other intance creation, you can use same key, if not, create a key and download, refer to other article, so you can ssh for advanced linux commandline control in ssh )
    7. After above steps, your instance should be running in your instance tab. with your tagged name (just wait for status from initializing to running)
    8. To find the admin pass, go instance > Action > instance setting > get system log, it will be there with notes like password is, default acc is “user”
  2. link domain name by updating zone file for ip record in Route 53 panel to the instance IP

AWS Route53 - the Domain manager

  • Route53 is basically the AWS console in charge of anything related to domain, like DNS management, domain purchase and transfer, and policy setting

Detail Steps

  1. in Godaddy, on your domain DNS page (maybe optional)
    1. export DNS zone file for backup reference
    2. change your DNS server to Route53's AWS DNS server (which you should have done when you moved your hosting to AWS, check on AWS EC setup guide first) (you can get your aws dns server url address in route53 page when trying create zone file. normally 4 dns server urls)
    3. (above step is suggested by AWS page, but later down the road during transfer domain stage, the page give you the option to use it or update DNS server, but if you setup above before hand, the transfer is quicker, and domain is online right after transfer)
  2. in Godaddy, on your domain manage page
    1. under privacy if your have: remove privacy
    2. under domain lock: turn off lock
    3. at the bottom of page, click Get authorization code, which will soon send you a email of the authorization code, which later will be entered on AWS route53 page
    4. once you have the code, click on the bottom of page, “Transfer domain away from GoDaddy”
    5. on the “Transfer domain away from GoDaddy”, it shows you 3 steps
      1. it will try to like you to stay with them and offer you discount, but never mind and click continue
      2. following the page, it may send you email to get confirm if needed. make your email box is open for checking on the side
  3. in AWS route53 page, on the left side panel
    1. click on “registered domains” tab, on the tab panel's top, click “Transfer Domain” button
    2. (Page 1.) Enter the name of your domain, and it will charge your one year of renew fee (that is why sometimes it is good when you domain is about to expire, then make the transfer, but of course give some buffer time, don't do at last minute, like say, 1 month before expire if you like)
    3. and click “Check” button, read the pop-in message if everything is ok or some steps you need to do before you do next, like DNS server setting mentioned before
    4. (Page 2.) next, domain option, where you enter your authorization code, and use 1st name server update option if you have done in above step, I use import name server from a Route 53 hosted zone that has the same name as the domain, which because I did when I was moving the hosting.
    5. (Page 3.) Enter domain contact info
    6. (Page 4.) Review and Purchase
    7. then you will receive a email from AWS about verify the email in contact info, both old email and new email (sometimes you may get the godaddy email first to approve transfer on your godaddy account).
      1. then in confirm page, click Yes for transfer
      2. then transfer is in progress
      3. soon, old domain host provider will email your about domain transfer,
  4. go GoDaddy your domain setting page, the pending transfer out will should on top link, or under domain > domain transfer, click view details
    1. in the pop-up, saying “Status: transfer not started. Accept or Decline”, and click the link and choose Accept to confirm transfer (if you dont do that, transfer will happen after a few days, but if you do that, it will transfer right now)
    2. Now go to domain list, you will see that old domain is not in Godaddy list any more
    3. and transfer should be done in minutes
  5. Then, AWS will email you to confirm your email address in contact info in domain transfer registration. just copy the link and paste to confirm page.
    1. Once you did that, the whole process is successful with notification email sent to you.
  6. go AWS route53 page's left panel, under “Pending requests” tab panel, no more pending transfer
  7. go AWS route53 page's left panel, under “registered domains” tab panel, your domain lives here now
    1. click the domain to review all the contact info and privacy setting
  8. you should get email from both AWS and Godaddy to confirm the final finish notification of domain transfer

Note

  • you have own multiple domains in your route53 page (which contains registration info and its dns name servers)
  • you don't need to create zone file for each domain if you don't plan to link it to a hosting yet.
    • thus, no zone file means no extra zone file charge yet.
  • under domain tab, click Register Domain button on top
    • you will add the list of domain you want to buy
    • then confirm all the registeration owner info
    • buy with card, then it will take 30 min to be ok to use
  • Note, after domain successfully registered
    • you will receive email on domain is ready for amazon owner email address and domain owner email address
    • zone file will automatically created for each domain, (with NS record and SOA record)
    • you can delete zone file if you don't want to use them immediately to avoid monthly per zone file charge (0.5 usd/m)
    • however, amazon recommend don't remote zone file but just delete record entry to avoid some risk,
    • To be continued on risk study

Long Term Cost Control

  • basic ec2 instance for hosting and domain hosting are quite cheap for AWS pay-per-use model, compared to other not-so-freedom shared hosting plan.
  • actually, they can get even cheaper (like half) by pre-pay annual ammount for so-called “reserved instance”
    • for more detail, you need to do some research
  • also, after the free tier, you may need plan on how low you can go with instance performance and how small you can set ebs disk storage (though some linux vm may pre-config with min disk size), thus this kind of super-budgeting can really cut the cost to bottom.

Problem and Fix

  • possible problem after that,
    • if you didn't use the amazon fix ip for your instance, your instance IP address and amazon dns instance address will be changed as well,
    • so in your DNS setting, you will need to update the IP address for your A record as well.