Showing posts with label amazon web services. Show all posts
Showing posts with label amazon web services. Show all posts

Wednesday, July 06, 2016

Recovering AWS AMI with lost key pair

If you lost a key pair for the running AMI or an image here is the sequence of steps to recover (ubuntu 14.04 style):
1. For the image, run an instance IN THE SAME AZ where you need your new AMI. If you got a running AMI in another AZ make an image and start the new AMI from that in the AZ where you need your new instance.

2. Once you got a running old AMI in the AZ you need, stop it (do NOT Terminate).

3. Detach volume of the old AMI using AWS Console

4. Start a clean new AMI with the key pair you got.

5. Using AWS Console, attach the detached old AMI volume to the new AMI. AWS will tell you it is mounted at /dev/sdf - NOT SURE IT IS THERE

6. SSH to your new AMI where you attached the old volume


#become a root
sudo -i

#find out where the old volume is attached
sudo lsblk --output NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,LABEL

#it should give you something like
NAME    TYPE SIZE FSTYPE MOUNTPOINT LABEL
xvda    disk   8G                  
└─xvda1 part   8G ext4   /          cloudimg-rootfs
xvdf    disk  14G                  
└─xvdf1 part  14G ext4              cloudimg-rootfs



#create mount point
mkdir /mnt/recovery

#mount the volume - note it is /dev/xvdf1 (with "1" at the end)
mount /dev/xvdf1 /mnt/recovery -t ext4

#copy SSH keys to the old volume. NOTE you will need 'ec2-user' instead of 'ubuntu' in the below pathes if you do it for other OS-s
cat /home/ubuntu/.ssh/authorized_keys > /mnt/recovery/home/ubuntu/.ssh/authorized_keys

#unmount the volume
umount /mnt/recovery/

7. Attach the old volume back to stopped old AMI

8. Now you can kill the new instance and start the old one. You should be able to SSH it with your key pair

Alternatively to steps (7)-(8) you can create a snapshot from the old volume with new key pair, and then create an image from that snapshot. Next, launch a new AMI from that image.

References:
[1]

Saturday, November 21, 2015

s3cmd for Ubuntu

Installing s3cmd on Ubuntu is really easy:

sudo apt-get install s3cmd
 
and then

s3cmd --configure


Note the utility saves .s3cfg file in your home directory (if not requested differently), so for another user you will have to re-configure it or copy your ~/.s3cfg file and modify it, or run

s3cmd -c ...

Trying it out:

echo "test" ~/test.txt
s3cmd --mime-type='plain/text' put ~/test.txt s3://mybucket 

Explicitly specifying the MIME type avoids s3cmd to do any guesswork trying to determine the file' MIME type.



Sunday, October 07, 2012

AWS Glacier Java Command Line Tool for PHP, Python, Ruby etc

For those of us who want to access Amazon Web Services Glacier from various environments and with a variety of programming languages I have developed an open-source (Apache 2 license) java command line app which operates AWS Glacier Vaults and Archives. The app is mostly based on AWS Java SDK samples from AWS documentation, e.g. http://docs.amazonwebservices.com/amazonglacier/latest/dev/creating-vaults-sdk-java.html

This project is hosted with Google Code: http://code.google.com/p/aws-glacier-app/
How to use the app: http://code.google.com/p/aws-glacier-app/wiki/Usage
And the ZIP with all the JARs is here: http://code.google.com/p/aws-glacier-app/downloads/list

Sunday, June 24, 2012

Converting AWS Keypair to Putty Keys

get puttygen.exe and run it

Use COnversions->Import menu to imnport AWS keypair.
Next, use "Save private key" button to generate putty' key.
In putty go to SSH->Auth and select putty' (PPK) file location