Saving a Customised Linux Amazon Instance

Posted By : Arvind Das | 19-Jun-2012

Amazon S3 is storage for the Internet. It is designed to make web-scale computing easier for developers.

Amazon S3 provides a simple web services interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, secure, fast, inexpensive infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud. It is designed to make web-scale computing easier for developers.

  • You should have an EC2 and S3 account already.If not Create
  • Create your Private key , Certificate key. To create these you must have an aws account. After successful creating your new account go to My Account>security credentials and download your keys.
  • You will also need your aws-access key and aws-security key. Download them.
  • Now go to your AWS account and select EC2. Launch one instance from here. Be sure to create a keypair and a server name.Then follow instructions to launch an instance. You can choose default settings for firewall or may configure it.
  • After you have launched your machine. Select checkbox of your instance in EC2. From the tab above it select connect and it will show an option like
  • Copy and paste below given command into your terminal and press enter. Now , you will be running your selected OS from root.
  •   ssh -i your_key.pem [email protected]
    
  • Download these files to your root directory.
  • Download ami tools using this command
  •     #wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip
        #unzip ec2-ami-tools
    
  • Downland EC2 API tools
  • #wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
    #unzip ec2-api-tools.zip
    
  • Install EC2 API and AMI tools
  • mv /root/ec2-api-tools-your-version-num /root/.ec2
    mv /root/ec2-ami-tools-your-version-num /root/.ec2
    cd /root
    
  • Copy your files from your local machine to remote machine. Place your keys in ~/.ec2
  • Set Path for ec2-ami and ec2-api tools.
  • vi .bashrc
    
  • place these commands in bashrc at the bottom
  • export EC2_HOME=~/.ec2/ec2-api-tools-your-version
    export PATH=EC2_HOME/bin:$PATH
    export EC2_AMITOOL_HOME=~/.ec2/ec2-ami-tools-your_version
    export PATH=EC2_AMITOOL_HOME/bin:$PATH
    export EC2_PRIVATE_KEY=~/.ec2/your-private-key.pem
    export EC2_CERT=~/.ec2/your-certificate-key.pem
    export JAVA_HOME=/usr/java/default/
    
  • save and exit(:wq)
  • after setting path,do
  • #source ~/.bashrc
    
  • You should be able to run the following command and not get an error:
  • # ec2-bundle-vol –help
    
  • Create your AMI Now we are going to take a snap shot of the running server. While still on the server run the following command:
  • # ec2-bundle-vol -d /mnt -k ~/.ec2/your_private_key.pem -c     ~/.ec2/your_certficate_key.pem -u XXXXXXXXXXXX
    
  • Where XXXXXXXXXXXX is your Amazon account number without the dashes.
  • Now wait a little and be patient while your images are being created.
  • Save your new AMI to S3. Now you have an AMI of your very own, but we need to save it to S3 so you can shut down your current AMI and start up your new one.
  • # ec2-upload-bundle -b [your-s3-bucket] -m /mnt/image.manifest.xml -a [aws-access-key-id] -s [aws-secret-access-key]
    

It’s better to create a bucket before you issue this command. Go to your S3 account and select an option to create a bucket. Register the AMI . You’ve now created an AMI and stored it on S3, but you still have to tell EC2 where the AMI is located so you can create an instance of it.
Go back to your terminal, and issue the command:

$ ec2-register [your_bucket]/image.manifest.xml

The command should respond with an AMI ID like ami-xxxxxxx. Use this key to start up an instance of your AMI.

When you run “ec2-bundle-vol” command to make backup of your instance second time , it shows and error.

About Author

Author Image
Arvind Das

Technical Product Manager experienced in developing Real Time Planning Solutions, Video CMS with experience in Product Management and technical expertise in Reactive applications , Micro-services . Spending most of his time in planning , new solutions.

Request for Proposal

Name is required

Comment is required

Sending message..