How to recover if you lost your key for an EC2 instance?

If you are running multiple instances, you probably use different set of keys. The optimum way to recover if you lost your key and can't login to your EC2 instance is:

  • Create an image of your running EC2 instance

  • Go to created image under Images > AMI

  • Select Actions > Launch

  • You can resize the EC2 instance if required

  • During launch, you can set a new key to use.

If you are troubleshooting what was wrong in your instance, you can also fix the
issue at this new launched instance. Once fixed you can replace the old instance with the new one behind ELB - Elastic Load Balancer.

If you have taken an image of an EC2 instance that are running docker images, than you need start the docker images before you plug it back to an ELB. Here is a tip https://forums.docker.com/t/what-to-do-when-all-docker-commands-hang/28103/5