DEV Community

Cover image for Migrate from AWS EC2 to Lightsail
David J Eddy
David J Eddy

Posted on

Migrate from AWS EC2 to Lightsail

Cross posted from my personal blog https://blog.davidjeddy.com.

As is good practice for any and all Cloud Engineers I am constantly looking for ways to minimize cost of operations and simpify operations. For this blog specifically it currently costs around 25 USD / mo. The costs comes from the EC2 instance, RDS ( + 14 day back ups), and a EFS volume, Route 53 domain, and outbound traffic. Looking around Lightsail is a much simpler and cheaper solution; so I started migrating.

AWS Lightsail in a nutshell

Lightsail is, ostensibly, a dumbed down UI for simple VPS administration. Servers can be provisioned, a SSH key is provided, port access, and disk snapshots are all available via the UI; a simplified UI. 

The Process

SSH into machine

This is standard fair Linux access. The Lightsail UI provides a download link for the *.pem file. Download it, move it to ~/.ssh, change permissions to 0400 and connect as normal. The UI also provides a web based SSH interface. I suspect this leverages AWS Systems Manager in the background.

Updated OS

Again, pretty standard fare, however I did an upgrade to Ubuntu 18.04. Call me brave but this is a personal blog site not a corporate payment system.

Install services

LEMP stack FTW

  • Nginx config is always all over the place. Configuration JSON files everywhere. Ugg.
  • PHP/PHP-FPM was easy as usual. I went with the Unix sock style configuration.
  • MySQL, DO NOT FORGET TO RUN THE HARDENING SCRIPT

Migrate Wordpress

With the core services install I move on to the unknown part of the migration. How to migrate Wordpress. Luckily Wordpress contains basic import / export functionality via the Settings menu item. 

WIN!

Took the output and imported it into the new instance. Everything went fine except the Link Directory content. That sucked, I had to find an alterate solution and migrate the content manually. :( Boo.

Update domain

With the content moved I went to Route 53 and setup a subdomain (https://blog.davidjeddy.com) and pointed it at the new static IP provisioned via the Lightsail UI. I then waited for propagation. Once I was sure blog.* pointed correctly I edited the TLD to redirect to blog.* thus not losing any organic traffic or mess with anyone's bookmarks.

Backups

This is the web, crashes happen. It is a fact of life. For LightSail backup up my application was as easy as clicking 'Create Snapshot' in the UI and the disk is imaged. I can even do this via the CLI API. Since the instance now contains my entire applications and database it is an all-inclusive backup. Be sure to test your recovery plan!

Decommission old infrastructure

Once I was sure everything was running I did a 'soft off' of the old location. Specifically added a banner to the top of the site indicating the move was happening. At the end of the week I checked traffic patterns to ensure the old instance was no longer receiving traffic. Then, lights off. 

Conclusion

Average cost before migration was running in the range of 25 USD / month. Projected cost after migration is around 10 USD / month. While not thousands per month this shows that AWS is serious about giving Linode / Dreamhost, other basic VPS providers a run for the money. Low cost + AWS infrastructure = market competition from the bottom to the top.

Top comments (13)

Collapse
 
benjaminblack profile image
Benjamin Black

I'm waiting for IPv6 before I will use Lightsail. I have been waiting for it since launch almost two years ago, and it's a little absurd that IPv6 wasn't supported at launch, in 2016, and still isn't supported.

Collapse
 
avasconcelos114 profile image
Andre Vasconcelos

Thank you for the article, I love seeing articles like these that help other folks instantly save costs on hosting their websites.

On a related note, I wanted to ask if there is any way to use https on LightSail without resorting to use their load balancer?

It's been costing me about $17/month, but it simply would not work without it when I tried to set it up with certbot

Collapse
 
david_j_eddy profile image
David J Eddy

Thank you Andre, glad you liked the article! Certbot should do the trick for you, it is how I do SSL on both Ubuntu 16/18, AMI (v2 does not work with cerbot w/o a LOT of work yet).

Send me a private message with your setup, may I can help.

Collapse
 
avasconcelos114 profile image
Andre Vasconcelos • Edited

Funny story went on here.

So I thought I had been setting up certbot wrong, as every time I tried testing if the page worked, the page would hang and the console would show its request status as pending.

What actually happened is that even though I opened up the ports in the server with sudo ufw allow 'Nginx Full', I hadn't set it up in the network tab on the lightsail screen. Going over to the Network options and adding the HTTPS option to the allowed ports fixed my issue!

Thank you once again as your article was the thing that finally made me want to fix the loadbalancer issue (and started saving me $18 every month!)

For reference, here's an image of the settings I had to add:

Thread Thread
 
david_j_eddy profile image
David J Eddy

:D Yea, Security Group's get me every time. Spent an hour recently trying to figure out why a site was return 504 Gateway Timeout. Turned out someone removed the SG's access to the RDS database. The language was timing out trying to connect to the DB so Nginx return 504.

Glad this helped out in some small way.

Collapse
 
latchuliz profile image
latchuliz

Here I having one staging server on AWS EC2 Ubuntu instance. But i want to migrate from EC2 instance to light sail. Is this possible? This is java based project. I want to copy all the data's and configuration files from EC2 to AWS light sail. I don't know how to do? Please tell me the procedure to do. It's urgent. I'm waiting for your reply

Collapse
 
david_j_eddy profile image
David J Eddy

I would not do this migration. EC2 is a much better option for commercial applications. Personal website, family photo gallery, low-budget / not-critical: LightSail.

If the application is a commercial product; go with EC2.

Collapse
 
lcdollarhite profile image
lcdollarhite

Mistype for route 53 at the beginning of the article.

Thank you for the insight into your migration experience.

Collapse
 
david_j_eddy profile image
David J Eddy

Good eye! Thank you for the correction.

Glad you liked the article.

Collapse
 
latchuliz profile image
latchuliz

How to move all data's and configuration files from EC2 instance to AWS Light sail? Please let me know if any procedure to follow. I want to move from EC2 instance to Light sail.

Collapse
 
david_j_eddy profile image
David J Eddy

While I have not attempted this type of migration personally; one idea that comes to mind is to copy the file system contents you wish to keep to S3 as an archive.

On LightSail download and expand the archive where you need it on the LightSail instance.

Please see my other comment concerning use of LightSail; TL;DR: LightSail should NOT be used for mission critical commercial applications.

Collapse
 
marataziat profile image
marataziat

Has google cloud this thing?

Collapse
 
david_j_eddy profile image
David J Eddy

I do not believe GCP has as similar offering for simplistic VPS hosting. However, I do know GCP does compute, database, and DNS. Just not in such a simple interface.