Creating a new EC2 instance

Continuing with AWS Stories let's try to create an instance from the console

You will need to create a new key-pair for associate with (in my case) the ubuntu user on the instance.
You will find a good reference for all the command in this stories here.

aws ec2 create-key-pair --key-name MyKey --query ‘KeyMaterial’ --output text > ~/.ssh/mykey.pem

You have only one chance to save the new key, so save it on a secure place (please avoid any kind of Cloud Computing storage)
In order to use in the future for SSH connections, modify the file privileges to Read Only just for me

chmod 400 ~/.ssh/mykey.pem

Time to create our first Security Group

A security group acts as a virtual firewall that controls the traffic for one or more instances.
aws ec2 create-security-group --group-name fw-kbit-web --description “Default Firewall”

Let's define some rules

If you want someone access your service, you should allow it.
In this case, we will enable SSH and HTTP access to everyone. This is not the BEST way to implement a Firewall, we can talk a little more in the near future.

# SSH Rule 
aws ec2 authorize-security-group-ingress --group-name fw-kbit-web --protocol tcp --port 22 --cidr
# HTTP Rule
aws ec2 authorize-security-group-ingress --group-name fw-kbit-web --protocol tcp --port 80 --cidr

Ready to build our first instance!

Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster.

Using everything together

My stories will focus on the AWS Free Tier resources.
In this case, we will bring ONE (count) Ubuntu 14.04 LTS instance (image-id) running a t2.micro instance (instance-type "Free Tier"). Using the resources we already created, let's bring this instance up!

aws ec2 run-instances --image-id ami-0fb83963 --count 1 --instance-type t2.micro --key-name MyKey --security-groups fw-kbit-web

Before close this chapter, we should assign a ElasticIP to our new instance. This is a best practice for instance you will use directly, without an Elastic LoadBalancer in front of it.

# Run to allocate one IP
aws ec2 allocate-address --domain standard
# Use the output to find the PublicIP and associate with your Instance
aws ec2 associate-address --instance-id i-***************** --public-ip ##.###.##.##

Then, try to connect over SSH, and show to the world your projects!

ssh -i .ssh/mykey.pem ubuntu@##.###.##.##
ubuntu@ip-###-##-##-###:~$ \o/

Keep reading -> AWS Resources

Like what you read? Give Javier Tomas Zon a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.