This article is going to cover getting started with Amazon EC2. This will cover the setup and launch of instances, along with the initial connection.
Firstly, log into AWS and select EC2 from the services list. There are a few menu items I’d like to cover at a high level:
Tagging enables you to tag your instances. So, you could tag your instance as being part of Dev, QA or Live environment. You could also tag an instance with the product name that is running on the instance. This is designed to help you search and find your instances faster.
Limits are the default limit of what you can do in AWS. For example, by default we are limited to a max of 20 EC2 instances running on our account. These limits are put in place to force you to consider whether you’re building your application in a sensible way. Further to this, you’re limited to 5 Ips, 5 VPCs and 40,000 provisioned IOPS. You can request that each limit is lifted.
It’s important to note that you can buy reserved instances through AWS. You can also sell your unused reserved instances. The longer you define the term to be, the cheaper your hourly price will become.
You can select different levels of offering for your reserved instance.
Light utilization is where you’ll be using the instances 30% of the time – great if you know that you have a busy period each day and don’t need a burstable instance 100% of the time. If you go over the additional 30% usage, you only pay for the time that you go over.
Each instance you launch will have a ‘tenancy’. That means that whenever your instance is rebooted, it always reboots on the same host machine (if its a dedicated tenancy) or on any host machine (when it’s shared).
Steps to test and play with this in AWS
To test all of this out in AWS, open the EC2 menu item from your dashboard and click ‘launch instance’.
When you’re choosing your instance type, it is important to note that you can import VM images to EC2, you can also build your own images.
Select the T2 micro instance and click next. Each instance is given 4 subnets (one for each availability zone). You can auto assign a public IP – this is not persistent and will change on shutdown. We can resolve this with an elastic IP, which we will discuss later.
When thinking about the instance tenancy, you’ll need to choose between one of the below:
Dedicated means that the instance will always reboot on the host machine
Shared means it can boot on any machine
If you look under the advanced tab, you’ll see where a user can pass a custom bash script that installs ‘stuff’ on launch. We will cover this in detail a little later.
Click next to add your storage. You can choose between SSD, provisioned storage or magnetic storage. For this use case, select SSD.
Through the next screens, create a new security group. Note: by default, all outbound traffic is allowed.
Select to launch the instance – you’ll now be prompted to select the key pair that you want to use (or create a new one).
If you now look in the instance details panel, you’ll see that we have a public and a private IP. The private IP is persistent, while the public IP is not. To make this persistent head to the ‘elastic IP’ menu on the left hand side.
Click allocate new address
You can now associate that address with your instance (the elastic IP will map itself to the private IP address)
It’s important to remember that you can detach the IP from one instance and apply it to another, without the IP changing. This is useful if you have an application that requires a static IP address. If one server has issues, you can simply redirect the IP to point at the backup server.
To connect to your instance, simply click “connect”. This will then show a popup with all the connection strings you need to get connected.
Use chmod400 to make your pem key read only to the owner
Use the connection string to connect to the server
Note: by default, EC2 user has sudo privileges
This article was brought to you by Netshock. Netshock aim to provide technology guides and insight to our readers