Running an AMI

From Bashlinux
Jump to: navigation, search

How to register an AMI

The AMI must be registered with Amazon EC2 in order to run instances, to do this run the following command:

# ec2-register bashlinux/bashlinux-general-server.fs.manifest.xml

then the AMI will be registered and the command will yield the name assigned, for this case the name is:

IMAGE	ami-43ab4f2a

If you cannot see the AMI name, you can try to run the following command

# ec2-describe-images -o self

and it will return a string with the details of each AMI into the bashlinux bucket

IMAGE	ami-43ab4f2a	bashlinux/bashlinux-general-server.fs.manifest.xml	367161194499	available	private		i386machine

How to generate a Keypair

One half of this keypair will be embedded into the instance created, allowing you to login securely without a password using the other half of the keypair. Every keypair need a name, so we can use the name of the image and run the following command:

# ec2-add-keypair bashlinux-general-server-keypair
KEYPAIR	bashlinux-general-server-keypair	2c:34:d7:d0:44:c5:06:07:3e:36:d3:99:9e:69:f2:5c:2f:ed:ab:47
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAmJ7Sl4k3FSXFHcpV0bluEcUcRXaOHEn+w3+zmnKe/dcbRh2lq+mYubQQl8hg
xmbPbD70gW8PxIqoG7FJwy4cEQhibuAyC5Fl9AsGetaC91fyoIA/veNuj+abIWiYHtrp9yGKZjRo
...
...
...
0OYLdAavg5dV9ftW9a/5hk01+iscqp5N30SJIwgOYDWDPJwdztLjTuqdfFVg2VpKswb/8SnsOb9v
OV/fvQHp+KxP6Ppjpxd1a7amAF2Kq+UMozXW9/iSZSKkVHiHwQjeLklFm5WOtpoW5OxvRQ==
-----END RSA PRIVATE KEY-----

then we create a file ~/.ssh/bashlinux-general-server-keypair and paste everything between (and including) the lines
-----BEGIN RSA PRIVATE KEY-----
and
-----END RSA PRIVATE KEY-----

To finish change permissions to the file

# chmod 600 ~/.ssh/bashlinux-general-server-keypair

How to run an instance

The command to launch an instance is

# ec2-run-instances ami-43ab4f2a -k ~/.ssh/bashlinux-general-server-keypair
RESERVATION	r-075c9f6e	367161194499	default
INSTANCE	i-ef79ad86	ami-43ab4f2a			pending		0		m1.small	2008-06-20T01:36:56+0000	us-east-1b

Then to check the status run:

# ec2-describe-instances i-577aae3e
RESERVATION	r-9f5c9ff6	367161194499	default
INSTANCE	i-577aae3e	ami-43ab4f2a	ec2-67-202-23-7.compute-1.amazonaws.com	domU-12-31-39-00-A2-02.compute-1 .internal	running	bashlinux-general-server-keypair	0	m1.small	2008-06-20T01:57:42+0000	us-east-1a

where the name is ec2-67-202-23-7.compute-1.amazonaws.com

How to authorize network access to the instances

Now that the image is running we need to authorize network traffic to the instance, run the following commands to accomplish with:

# ec2-authorize default -p 22
GROUP		default
PERMISSION		default	ALLOWS	tcp	22	22	FROM	CIDR	0.0.0.0/0
# ec2-authorize default -p 80
GROUP		default
PERMISSION		default	ALLOWS	tcp	80	80	FROM	CIDR	0.0.0.0/0

How to connect to the launched instance

Now that network is authorized you can connect using the following command:

ssh -i bashlinux-general-server-keypair [email protected]

How to link a public IP address to the instance

Allocating IP address
Now that the instance is running it only has a private IP, in order to allocate an public IP address run the following command:

# ec2-allocate-address
ADDRESS	75.101.129.154

Associating IP address
The IP address the gave us the above command must be added to the associate command as follows:

# ec2-associate-address -i i-577aae3e 75.101.129.154
ADDRESS	75.101.129.154	i-577aae3e

The instance can be now accessed typing in the browser ec2-75-101-129-154.compute-1.amazonaws.com