Lightsail offers an effortless server experience with a generous 3-month free tier. While it may limit your control over the server compared to other options, it’s perfect for those needing reliable website hosting without extensive customization.
Opting for a serverless, fully managed solution like Lightsail can sometimes come at a higher cost, but it also brings peace of mind and less administrative burden compared to traditional Infrastructure as a Service (IaaS) alternatives like EC2.
On the other hand, EC2 provides a more customizable and robust solution, with a generous one-year free tier plan. It’s ideal for those who require greater control over their server environment or have more complex needs beyond a WordPress website.
In many cases, migrating from AWS Lightsail to AWS EC2 makes sense due to factors such as cost and flexibility. Follow the instructions below to learn how to seamlessly export your Lightsail instance to EC2.
Note that you export your instance from EC2 to Lightsail back, you might want to store a snapshot of your instance or not delete your Lightsail instance until you are sure.
Prerequisite
- You have an AWS account registered.
- You have created an AWS Lightsail instance.
- You are attentive on the AWS dashboard, You check your region on AWS dashboard very frequently to ensure you are using the right region otherwise, you might encounter so much confusion and blocking.
Make a snapshot of your Lightsail instance
- From your AWS dashboard after you have logged in, search for Lightsail on the search bar above or click on Service at the top and select Lighsail. You will be taken straight to the Lightsail page.
- On the Lightsail page, click on a snapshot from the options list.
- You will the list of available snapshots, click Create Snapshot, You will be required to give it a name, then click on Create this will take some time to complete, about 3 to 7 minutes.
- After creating the snapshot, It will listed among the list of available snapshots, click on the one you just created to see more details about it. It will be open.
Note that your snapshot can be used to restore your Lightsail instance to the exact state it was when you took the snapshot.
After successfully creating the image you can delete the snapshot because it will be charged on your account but I recommend you don’t so that it you can use it to restore the image just incase of any issues going forward.
Transfer your Lightsail snapshot from Lightsail to EC2
- Open your newly created snapshot page, to see more details.
- Click on the three dots at the right side of the snapshot, on the option, click on Export to Amazon EC2. Click on Yes, Continue button in the pop-up and the Acknowledge button in the next pop-up.
- You will see a dropdown indicating the transfer of the snapshot to EC2.
The transfer will take some time to complete, about 20 minutes.
- After the transfer is completed, from your AWS account go to the EC2 page (Click on the Services and select EC@ from the dropdown or search for EC2 from the top search bar and select it. You will taken to the EC2 dashboard.
- On the EC2 dashboard click on Snapshots from the Elastic Block Store option. Your LIghtsail will be listed on the page when it’s loaded.
- Select the Snapshot, click on Action, and select Create Image from Snapshot.
- Give the image a name and click on Create Image button at the bottom.
After successfully creating the image you can delete the snapshot because it will be charged on your account but I recommend you don’t so that it you can use it to restore the image incase of any issues going forward.
If you delete your Lightsail instance then you should delete your Elastic IP address assocaited with the instance else you will be charged for the unattached IP address. follow the process below.
- On your AWS dashboard, click on the Services button, select Networking from the dropdown, or search for networking on the search bar above and select networking.
- Select Elastic IP from the options on the left of the networking page.
- Locate the unattached IP of your Lightsail instance from the list of Elastic IPs available.
- Select the IP and click the Actions button, select delete, and confirm the delete on the pop-up.
Create an EC2 instance from the AMI gotten from your Lightsail snapshot
- After successfully creating the image, from your EC2 management console, click on AMI from the left side options under Images.
- Select the AMI you just created and click Launch Instance from AMI.
Complete the resulting form. - Give your instance a unique name.
- Depending on your application requirements, choose your machine type but note that t2.micro is free tier eligible which means you can use it for some time and not be charged for it. I recommend it if you are just trying things out.
- Select an existing Key pair or create a new one if you have not created one before. Note that key pairs are used for you to connect to your instance once created and it is downloads once after which you can’t download again.
- Under Network, select an existing security group or create a security group that enables access to your instance using HTTP, HTTPS, or SSH.
- Leave other parameters unaltered except you have specifications to follow.
- Click Launch Instance.
- Wait for the instance to become available, you can confirm this when you go to your instance page (from the EC2 page options click on instances) shows Running and 2/2 checks passed.
- Click your instance and see more details about your instance, note the Public IPV4 address, Public DNS address.
Connect to your EC2 instance using SSH
There are various ways to connect to your instance, on your instance page click on Connect button at the top to see the options.
We will focus on two of the options; Browser based SSH and local shell connection.
Connecting to EC2 instance directly from the browser based SSH
- Click on the instance and from the instance page click on Connect button from the top of the page or select the instance and click on Connect at the top of the page.
- Select Connect using EC2 instance connect and put the username of your instance, try out the default username “root”.
If the default username does not connect, try out different username, ec2-user, admin, Bitnami, etc. Bitnami worked out well for me.
See the list of default username for different EC2 linux distribution
If you encountered error on connecting, check out your Security Group (SG) for the instance, Access Control List (ACL) for the VPC also check out security configuration for the VPC to ensure it allows inbound and outbound SSH traffic.
Connecting to EC2 instance using local SSH client
You can connect through SSH to your instance locally on Linux OS, Windows OS and MAC OS. check out the options below.
Linux and macOS
You can connect to EC2 instance from a local Linux Operating system using SSH from your Linux command line. I have written a lot about it on the page linked below.
Connect to EC2 instance from Linux OS using SSH.
Windows
You can connect to your AWS EC2 instance from a local Windows Operating system using SSH client using either OpenSSH or PuTTY. Also, you can use Windows WSL (Windows Subsystem for Linux) to connect using the Windows emulated Linux command line to connect like a Linux system.
I have written a whole lot of it on the page linked below.
Connect to EC2 instance from Windows OS using SSH.
Setup your Lightsail instance
- After connecting to your instance using one of the methods above, open this directory ~/.ssh/authorized_keys on your instance. Use these commands below to do this –
cd ~/.ssh/authorized_keys
nano authorized_keys
- On the text file, delete the LightsailDefaultKeyPair from the text file. Check through the file carefully.
- Follow the commands below to save changes, confirm the filename, and exit nano
Ctrl + O
Enter
Ctrl + X
Enable Domain name for your EC2 instance and hTTPS connection
Enable Domain name
After successfully exporting your Lightsail instance to EC2, you can now access your website, click on the public IPv4 address of your instance and see the content of your website show up. Ensure you click on the public address and not the private address as that is not usable on the internet (external networks).
But your website is not best to use an IP address, you need to enable a domain name for it to be user friendly, reputation, and bookmarking. You can buy domain name from GoDaddy, NameCheap, Route53(AWS owned).
If you cannot not access your website via the public IP address, check out your Security Group (SG) for the instance, Access Control List (ACL) for the VPC also check out security configuration for the VPC to ensure it allows inbound and outbound SSH traffic.
I have written a detailed explanation of these here- Enable a Domain name for your website hosted on EC2 instance.
Enable HTTPS connection
After connecting to your EC2 instance using SSH, You can now configure the https conncetion for your instance. This is important if you are hosting a website on your EC2 instance.
By default Your EC2 instance allows only HTTPS connection which is not accepeted by most browsers like Chrome because it is not secure. You need a secure connection to servers for various reasons; integrity, privacy, etc.
Follow the steps to enable HTTPS for your EC2 instance.
- Connect to your instance through SSH.
- Install bncert tool on your website. Use command wget -O bncert-linux-x64.run https://downloads.bitnami.com/files/bncert/latest/bncert-linux-x64.run
- Create a directory for the file on your instance. Use command sudo mkdir /opt/bitnami/bncert
- Move the downloaded file to the new directory. Use command sudo mv bncert-linux-x64.run /opt/bitnami/bncert/
- Make bncert generate a file that can be run executed as a program. Use command sudo chmod +x /opt/bitnami/bncert/bncert-linux-x64.run
- Create a symbolic link that run the bncert tool. Use command sudo ln -s /opt/bitnami/bncert/bncert-linux-x64.run /opt/bitnami/bncert-tool
- Run bncert tool on your instance. Use command sudo /opt/bitnami/bncert-tool
- Fill up the info, as follows-
- Domain list – put in your domain and sub domain i.e example,com and www.example.com
- Enable HTTP to HTTPS redirection – Y
- Enable non-www to www redirection – N or Y depending on your needs.
- Enable www to non-www redirection – Y or N should be reversed of the last option.
- Put Y to confirm your request
- Put in your email address as requested.
- Review the Let’s Encrypt Subscriber Agreement. Type
Y
and press Enter to accept the agreement and continue.
The actions are performed to enable HTTPS on your instance, including requesting the certificate and configuring the redirections you specified.
From your Instance page click on the Public IPv4 address, it should open on a new tab, if it uses http then modifiy the url to use https, confirm that it opens on https.
I have written a detailed post on how to enable https for Lightsail instance which is the same procedure as for EC2.
Conclusion
By following the procedures stated above, you should have successfully moved your AWS Lightsail instance from Lightsail to EC2 and access it at the same state you moved it from, this can save cost and enable more on your instance. If you saved your Lightsail snapshot you should be able to restore your Lightsail instance anytime you want at the state you save it at. You should know that you cannot carryout the reverse, exporting EC2 instance to Lightsail.
You had difficulties, let me see your comment. Read more from the blog and follow me on socail media.