By using AWS re:Post, you agree to the Terms of Use
/Can't connect to Lightsail instance/

Can't connect to Lightsail instance


I wanted to connect to my database remotely and did some modifications to allow this. Followed the instructions in the Connect To MariaDB From A Different Machine page. Hit a bump in the first step; the ufw command was not recognized. So I tried to find a way to install it and followed the instructions in the -bash: ufw: command not found (ubuntu 18.04) page.

I did all that and now I can't connect to my instance. The site in the instance is inaccessible. Can't connect using SSH or FTP. Can't ping the IP.

Restarting the services and/or the instance did not work. If I click on the "Connect using SSH" button in the instance page (in the Lightsail console) and wait long enough, I get the following error:

An error occurred and we were unable to connect or stay connected to your instance. If this instance has just started up, try again in a minute or two.


How can I regain access to my instance back? If the instance is not salvagable, is there a way to, well, salvage the database (and maybe the project files)?

1 Answers
Accepted Answer

Hi Akinuri,

Enabling ufw on a Lightsail instance can block you out of your instance. This has happened to me a while ago. You cannot ssh or connect to your instance through a browser-based ssh client. To recover my instance I took a snapshot of it since I did not create a backup on launch and created a new instance from it. You can use your backup if you have. When you launch the new instance via console add the following script as a launch script to disable ufw:

sudo service ufw stop

You can also use AWS CLI to launch the new instance from a snapshot by running the following command:

aws lightsail create-instances-from-snapshot --region <snapshot-region> --instance-snapshot-name <snapshot-name> --instance-names <new-instance-name> --availability-zone <preferred-AZ> --user-data 'sudo service ufw stop' --bundle-id <value>

Alternately, you can export your Lightsail snapshot to Amazon EC2 by following the steps here and here. Additionally, here is a video tutorial on how to export Lightsail instance to Amazon EC2 instance.

Hope this helps

answered 19 days ago
  • Hi. I tried creating a new instance from a snapshot (that is taken after the problem), but all I did was reboot the instance, which did not help. I tried the launch script approach twice, and it did not help, at first. Then I started looking into the EC2 approach. While doing that, I tried to connect to the instance (that run a launch script) again and it worked. I guess I had to wait some time. Exported the db and the files and moved to a new instance. So, thank you :)

  • Also, since the instance with lauch script worked while I was halfway with the EC2 approach, there were some snapshots, volumes, etc. in the EC2 console. I started a clean up; deleted an instance, an AMI, a volume, and a snapshot. Then I checked the Resources card in the Dashboard and I saw one in Security groups.

    There seems to a resource, VPC. I'm not familiar with this. Was this created with the "Export to Amazon EC2" task? Or was it always there (and somehow related to Lightsail)? I'm not sure if I should delete it.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions