This blog is to help you get started with AWS EC2. We have written two parts for create instance and deployment. Part 1 is for “How to Create an EC2 Instance from Scratch” and Part 2 is for “How to setup Rails Application using Nginx, Passenger”
Create Amazon EC2 Instance :
1. Login into the EC2 dashboard in the AWS Management Console
https://console.aws.amazon.com/ec2
2. Find the services on the top of the header, click on services option and select EC2 service from compute section.
3. Click on Lunch Instance button. It will open new instance wizard page.
4. Choose an Amazon Machine Image (AMI) : Click on the Select button as per your requirements. We are selecting ubuntu server for demo purpose as of now: Ubuntu Server 16.04 LTS (HVM), SSD Volume Type – ami-759bc50a (64-bit)
5. Choose an Instance Type: Select any appropriate instance type. In the screenshot, we are selecting a t2.micro (Free tier eligible) instance, which is normally selected by default and is sufficient for demo purposes. It provide you free 1GB RAM.
6. Configure Instance Details : We don’t need to change anything for demo purpose. Leave as it is all the options, then click the Next: Add Storage button. We are selecting default as of now: vpc-70e14e0b (default)
7. Add Storage : Leave the defaults and Click the Next: Add Tags button.
8. Add Tags : Click on the Add Tag button. Type Name in the Key field, and in the Value field type the instance name.
9. Configure Security Group:
Assign a security group – Select create a new security group.
Security group name – Name of the group. Ex: security group demo
Description – Description of the group.
Set the rule for SSH, by selecting or setting the following values. They allow inbound SSH connections from all sources (any IP address):
Type: SSH, Protocol: TCP, Port Range:22, Source: Custom 0.0.0.0/0, Description: Accept SSH connections from all sources
Create some rules that allows inbound HTTP and HTTPS connections from all sources. Click on Add Rule button.
Type: HTTP, Protocol: TCP, Port Range: 80, Source: Custom 0.0.0.0/0, Description: Accept unencrypted HTTP connections from all sources
10. Review Instance Launch: Click the Launch button. To change settings, click on the
Previous button to go back.
11. Launch: When you click the Launch button, a modal pops up asking you to select an existing key pair or create a new key pair. Select Create a new key pair, Once new key pair is created you
must have to download that .pem file then after click on the Launch Instances button.
Click on launch status then after click the View Instances button.
The instances you have created so far are listed on the Instances dashboard. The following
screenshot shows a single instance.
12. Create Security Group: A security group acts as a virtual firewall to control the traffic for its associated instances. Set inbound rules to control incoming traffic to the instance, and set outbound rules to control the outgoing traffic from your instance.
You need to do only for the first instance because all instances can use the same security group.
- Select Security Groups.
- Open the Inbound tab and verify that the rules you created are listed or not.
- Click on Outbound tab and click the Edit button to create a rule for outbound traffic.
13. We have created instance with public IP. So public IP will be change once you restart your server. So for making static IP we need to create Elastic IPs.
- Select Elastic IP’s from sidebar options.
- Click on Allocate new address. Then select platform as per the requirement and click on allocate.
- It will allocate new Elastic IP automatic.
- You can check elastic IP from Elastic IPs option like below. You can set anything in name field.
- Now the next step it to set our instance to elastic IP. For that select Action >> Associate Address. It will open new screen like below. Select resource type as per the requirement. We have selected instance as resource type. Then select instance from the list. Then select private IP from the list. We have select private IP of the created instance. Then select allow Elastic IP if you have already attached. Then click on associate button.
- For checking elastic IP to our instance
14. Now your instance is ready to use. You can login to the server. For login you must follow below steps:
- Move your .pem file to specific path. EX: Desktop
- Set permission mode of the .pem file. EX: chmod 400 nginx-passenger-demo.pem
- Login instance using ip and pem file.
ssh -i “nginx-passenger-demo.pem” [email protected] - It will give you welcome screen of the instance.
“Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-1061-aws x86_64)”