Since the AWS web console crashes so frequently, using ec2 command line tools is neccessary.
Some useful usage of command line tools:
Look up the AMIs:
where_your_ec2_certifications/ec2-describe-images -o YOUR_12_DIGITS_ACCOUNT_NUMBER
Start up an Instances:
where_your_ec2_certifications/ec2-run-instances AMI_ID -k KEY_PAIR_NAME -g SECURITY_GROUP_NAME
Describe the Status of Instances:
where_your_ec2_certifications/ec2-describe-instances
Terminate an Instance:
where_your_ec2_certifications/ec2-terminate-instances i-xxxxxxxx (your instance id)
My Reference:
http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
標籤
- ASP .NET
- Cloud Computing
- Others
- Perl
- Ubuntu
- Unix Command
- Visual Studio
2010年6月22日 星期二
2010年6月7日 星期一
Creating your own Amazon Machine Image (AMI) on Elastic Compute Cloud (EC2)
Creating your own Amazon Machine Image (AMI) on Elastic Compute Cloud (EC2)
Two References I Read:
1. http://www.philsergi.com/2009/10/customizing-ec2-ami.html
2. http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
Before Everything You Sart:
You need a AWS account. I assume that you already have one.
Download the Amazon EC2 API Tools:
Download it by google or "wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip".
Note that the following sections just provides some solutions work for me.
You may have your own solutions with/without this tool set.
After unzipping the tool set, create a dir "~/.ec2" and moving everything to here.
Create/Modify "~/.bash_profile":
This should be done on your LOCAL machine.
Please open the file "~/.bash_profile" and add these lines:
====
export EC2_HOME=$HOME/.ec2
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=$EC2_HOME/pk-xxxxxx.pem
export EC2_CERT=$EC2_HOME/cert-xxxxxx.pem
export JAVA_HOME=/usr/lib/jvm/java-6-sun
====
Note that you need to change your shell to be bash. You can use "chsh" to change your longin shell to bash.
Note that the pathes shown above are just examples. Please specify your pathes.
I will explain how to get pk-xxxxxx.pem and cert-xxxxxx.pem in coming section.
Once you acquire these file, you need to replace the "xxxxxx" to your code.
Acquiring X.509 Certifications and Key Pairs:
You need to go to the "Security Credentials" page.
https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
For X.509 Certifications, got to "Access Credentials" section, the "X.509 Certificates" tag and create a new Certificates.
Then you can download the certification and private key. They are the pk-xxxxxx.pem and cert-xxxxxx.pem.
For the key pair, you can just go to the AWS console and create one.
https://console.aws.amazon.com/ec2/home
Go the the "NETWORKING & SECURITY" section, "Key Pairs" tag, create one, and download another .pem file.
Launch an Instance:
Please Lauch an Instance. You can do it via AWS console.
Please select the key pair name which is the same as the one you just created.
Wait for the status of the instance to be "running" and ssh to the "public DNS".
SSH to the Instance:
My solution is using putty. Please specify the authentication under "SSH -> Auth".
The file you should specify is the "key pairs" .pem file.
Upload the pk-xxxxxx.pem and cert-xxxxxx.pem to the instance. You can use arbitrary way. My solution is using sftp command.
Then do "cp pk-xxxxxx.pem /mnt" and "cp cert-xxxxxx.pem /mnt".
Bundle the Customized AMI:
Please do this on EC2 Instance:
ec2-bundle-vol -d /mnt -k /mnt/pk-xxxxxx.pem -c /mnt/cert-xxxxxx.pem -u aws_account_id-s 10240 -r i386
For the aws_account_id, it is a 12 digits number. You can find it by logging into AWS and going to personal information page.
It is your account-number.
Upload AMI Bundle To S3:
Please do this on EC2 Instance:
ec2-upload-bundle -b bucket_name_key -m /mnt/image.manifest.xml -a access_key_id -s secret_access_key;
You can find the access_key_id and secret_access_key id on "Security Credentials".
http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
Go to the "Access Credentials" section and "Access Keys" tag.
Register the AMI:
You can do this on LOCAL machine:
ec2-register bucket_name_key/image.manifest.xml
But, in fact, you can do it on AWS console.
Go the the AMI tag and register the AMI. Note that the bucket_name_key should be the exactly same with the name you specify in the "Upload AMI Bundle To S3" step.
Two References I Read:
1. http://www.philsergi.com/2009/10/customizing-ec2-ami.html
2. http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
Before Everything You Sart:
You need a AWS account. I assume that you already have one.
Download the Amazon EC2 API Tools:
Download it by google or "wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip".
Note that the following sections just provides some solutions work for me.
You may have your own solutions with/without this tool set.
After unzipping the tool set, create a dir "~/.ec2" and moving everything to here.
Create/Modify "~/.bash_profile":
This should be done on your LOCAL machine.
Please open the file "~/.bash_profile" and add these lines:
====
export EC2_HOME=$HOME/.ec2
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=$EC2_HOME/pk-xxxxxx.pem
export EC2_CERT=$EC2_HOME/cert-xxxxxx.pem
export JAVA_HOME=/usr/lib/jvm/java-6-sun
====
Note that you need to change your shell to be bash. You can use "chsh" to change your longin shell to bash.
Note that the pathes shown above are just examples. Please specify your pathes.
I will explain how to get pk-xxxxxx.pem and cert-xxxxxx.pem in coming section.
Once you acquire these file, you need to replace the "xxxxxx" to your code.
Acquiring X.509 Certifications and Key Pairs:
You need to go to the "Security Credentials" page.
https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
For X.509 Certifications, got to "Access Credentials" section, the "X.509 Certificates" tag and create a new Certificates.
Then you can download the certification and private key. They are the pk-xxxxxx.pem and cert-xxxxxx.pem.
For the key pair, you can just go to the AWS console and create one.
https://console.aws.amazon.com/ec2/home
Go the the "NETWORKING & SECURITY" section, "Key Pairs" tag, create one, and download another .pem file.
Launch an Instance:
Please Lauch an Instance. You can do it via AWS console.
Please select the key pair name which is the same as the one you just created.
Wait for the status of the instance to be "running" and ssh to the "public DNS".
SSH to the Instance:
My solution is using putty. Please specify the authentication under "SSH -> Auth".
The file you should specify is the "key pairs" .pem file.
Upload the pk-xxxxxx.pem and cert-xxxxxx.pem to the instance. You can use arbitrary way. My solution is using sftp command.
Then do "cp pk-xxxxxx.pem /mnt" and "cp cert-xxxxxx.pem /mnt".
Bundle the Customized AMI:
Please do this on EC2 Instance:
ec2-bundle-vol -d /mnt -k /mnt/pk-xxxxxx.pem -c /mnt/cert-xxxxxx.pem -u aws_account_id
For the aws_account_id, it is a 12 digits number. You can find it by logging into AWS and going to personal information page.
It is your account-number.
Upload AMI Bundle To S3:
Please do this on EC2 Instance:
ec2-upload-bundle -b bucket_name_key -m /mnt/image.manifest.xml -a access_key_id -s secret_access_key;
You can find the access_key_id and secret_access_key id on "Security Credentials".
http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
Go to the "Access Credentials" section and "Access Keys" tag.
Register the AMI:
You can do this on LOCAL machine:
ec2-register bucket_name_key/image.manifest.xml
But, in fact, you can do it on AWS console.
Go the the AMI tag and register the AMI. Note that the bucket_name_key should be the exactly same with the name you specify in the "Upload AMI Bundle To S3" step.
訂閱:
文章 (Atom)