Getting started on EC2

EC2 is the abbreviation for Amazon Elastic Compute Cloud. This service consists in the usage of computers instances existing in the cloud which we can use in the same manner as if they would be in our own desktops. The EC2 service is highly flexible giving the developer the ability to choose for the instance the hardware capacity, such as memory, CPU, hard drive space, as well as the software configuration, such as operating system, installed application and packages, network configuration among others.

How to create an EC2 instance and connect to it?

The creating flow for an EC2 instance can be easily done through the AWS console. Go to services EC2 and then EC2 Dashboard. The normal flow is divided in the steps detailed below.

1. Choosing a basic image.

The selected image comes with a set of basic resources installed. The right option for us depends on what we want to develop and if it important an specific OS. But in general, or at least for the projects we manage at CDS, the Linux image is the right one most of the times. It is importan to mention that you can also create custom images, also known as AMI that can be used in the future as the base for other instances. For example you create a basic Linux instance, then you install git, npm and node js. You can save a new AMI with the configuration and the next time you need a instance with those things installed you can use it again.

2. Choose an instance type.

Here we specify the hardware properties which basically depends on the things we need to support. For example if we want to deploy a game we might want to choose an instance with high card graphics resource. For a general purpose, an m3.medium is a very good choise. If you are wondering how will work my app with the free t2.micro instance, well, the free things are free for something. This instance has very low resources thus is very common your application becomes unavailable after a while.

3. Set storage.

This indicates the space for the hard drive attached to the instance. The size selected for this depends if we plan to store a database or local files on the instance. Otherwise it would be enough with just a few GB.

4. Security groups

Security groups as its name describes in in charge of setting up security access into the instance. The configuration is based on inbound/outbound rules allowing network access to your application. Normally for a web app we want to have port 80 open to the world and port 22 for SSH access. Usually the default security group is enough to get started.

5. Create an API key

This key will provide SSH access into the instance allowing us to manipulate and install the machine on the cloud same was as we do it locally. Put a nice name, store it safely and don't share with anyone else besides your teammates.

6. Monitor and connect to the instance

Finish the setup and wait a few minutes while things get cook. Take a look to the EC2 Dashboard where you can found information about the instance and its performance status. In order to connect to the instance we should use the key described in the last point. Run the following command on your console to access the instance: ssh -i your_key_file.pem ec2-user@ec2-instance-ip

Where ec2-instance-ip is clearly your instance's IP address which you can also found in the Dashboard. In case you receive an error with the above command you might need to set proper permissions to the KEY. Try running chmod 400 your_key_file.pem

For further reading on this topic please visit this.

Next steps

Is very common for a project the need to store files such as images, videos, or any other content. AWS provides another great service for files storage and management: S3