AWS




What is EC2 in AWS?

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud.



How to launch Amazon Linux EC2 Instance?

We need to follow below steps:

Step 1: Sign in AWS Account. Click on the EC2 icon under Recently visited services. If it is not visible search EC2 in the search bar. Then click on the EC2 icon.

AWS-EC2-LAUNCH

Step 2: Click on Launch instance -> Launch instance Button.

AWS-EC2-LAUNCH

Step 3: Choose any Machine. Here I choose Amazon Linux 2. Then click on the Select button.

AWS-EC2-LAUNCH

Step 4: Select machine type. Here I choose t2.micro. Then click on Configure Instance Details button.

AWS-EC2-LAUNCH

Step 5: In this screen If you want you can Configure Instance Details. Then click on Add Storage button.

AWS-EC2-LAUNCH

Step 6: In this screen, you can change Volume Size and Volume Type as well as also Add New Volume. Then click on Add Tags button.

AWS-EC2-LAUNCH

Step 7: In this screen, you can add Tag Name for adding tag name click on Add Tag button and enter tag name. Then click on Configure Security Group button.

AWS-EC2-LAUNCH

Step 8: In this screen, you can Add Rule like allow Protocol and Port Number. Then click on the Review and Launch button.

AWS-EC2-LAUNCH

Step 9: In the Review Instance Launch screen you can verify all details then click on the Launch button.

AWS-EC2-LAUNCH

Step 10: In this screen, you can choose: Select an existing key pair or create a new key pair. If you did not create any key pair already or if you want to use new key pair then select Create a new key pair option. Give key pair name and click on Download Key pair button.

AWS-EC2-LAUNCH

Step 11: If you want to use existing key pair then Choose an existing key pair option. Then click on the check box and then click on the Launch Instances button.

AWS-EC2-LAUNCH

Step 12: In this screen, you can see Instances Launch Status. Click on Instance ID.

AWS-EC2-LAUNCH

Step 13: In this screen, you can see created Instance.

AWS-EC2-LAUNCH

How to Stop EC2 Instance?

Below Actions need to perform for stop, running ec2 instance.

Click on the Actions button -> Instance State -> Click on Stop Button

AWS-EC2-STOP


Click on the Yes, Stop button.

AWS-EC2-STOP


How to Start EC2 Instance?

Below Actions need to perform for start, stopped ec2 instance.

Click on the Actions button -> Instance State -> Click on Start Button

AWS-EC2-START

OR

Select ec2 instance -> Click on Instance state -> Click Start instance

AWS-EC2-START

Now instance will start.


How to Delete/ Terminate EC2 Instance?

Below Steps need to perform for the delete ec2 instance.

Step 1: Select ec2 instance.

Step 2: Click on Actions button -> Instance State -> Click on Terminate button

AWS-EC2-TERMINATE

Step 3: Click on the Yes, Terminate button.

AWS-EC2-TERMINATE

Step 4: Now, the ec2 instance terminates.

AWS-EC2-TERMINATE

Different ways to connect to EC2 instance

  • Using Command Prompt to connect EC2 instance
  • Step 1: Click on Connect button.


    AWS-EC2-CONNECT-COMMAND-PROMPT

    Step 2: Click on the SSH Client tab and copy the selected command.


    AWS-EC2-CONNECT-COMMAND-PROMPT

    Step 3: Open a command prompt and go to the pem file location. Which is download/ selected at the time of ec2 instance launch time. Paste copied command here. Press enter key. If the message "Are you sure want to continue connecting" comes. Type Yes and press Enter key.


    AWS-EC2-CONNECT-COMMAND-PROMPT

    Step 4: If you are facing the below permission-related issue. Then you have to give proper permission to pem file. Here I am using the windows system them below steps need to be required related to permission.


    AWS-EC2-CONNECT-COMMAND-PROMPT

    Step 5: How to solve .pem file bad permissions issue?

    Click Here for steps solve .pem file bad permissions issue

    Step 6: Now Repeat Step 3. [Copy ssh command in command prompt]


    AWS-EC2-CONNECT-COMMAND-PROMPT

    Step 7: Now ec2-instance is connected. Disconnect ec2-instance type “exit”. Press Enter key.


    AWS-EC2-CONNECT-COMMAND-PROMPT

  • Using FileZilla to connect EC2 instance
  • Step 1: Download and install FileZilla in your system if it is not already installed in the system. Here you have required .ppk for connecting ec2 instance using FileZilla. If you don't have .ppk file follow Step 2 otherwise skip it.


    Step 2: How to generate .ppk file from .pem file?

    Click Here for steps generate .ppk file from .pem file

    Step 3: Open FileZilla. Then click on the Edit button. Click on the Settings button.


    AWS-EC2-CONNECT-FILEZILLA

    Step 4: Go to the left side mentioned path. Then click on Add key file… Button.


    AWS-EC2-CONNECT-FILEZILLA

    Step 5: Select the ppk file in your system location. Then click on Open Button.


    AWS-EC2-CONNECT-FILEZILLA

    Step 6: Now you can see the ppk file imported successfully. Click on Ok Button.


    AWS-EC2-CONNECT-FILEZILLA

    Step 7: Copy ec2 instance public IP address.


    AWS-EC2-CONNECT-FILEZILLA

    Step 8: Now put ec2 instance public IP address inside Host: Text Field. Ec2 instance user name inside Username: Text Field. 22 port number inside Port: Text Field. Click on the Quickconnect button. Click on the OK button.


    AWS-EC2-CONNECT-FILEZILLA

    Step 9: Now ec2 instance is connected.


    Note: Before upload or download a file selects the proper destination path. Where file should be put.


    Now you can upload the file in the ec2 instance. Right-click on the file then click on the Upload button.


    AWS-EC2-CONNECT-FILEZILLA

    You can download the file in the ec2 instance. Right-click on the file then click on the Download button.


    AWS-EC2-CONNECT-FILEZILLA

  • Using PuTTY to connect EC2 instance
  • Step 1: Download and install PuTTY in your system. If it is not already installed in the system. Here you have required .ppk for connecting ec2 instance using PuTTy. If you don't have .ppk file follow Step 2 otherwise skip it.


    Step 2: How to generate .ppk file from .pem file?


    Click Here for steps generate .ppk file from .pem file

    Step 3: Open PuTTY. Select left side path location then click on the Browse button and select .ppk file from your system. Click on the Open button.


    AWS-EC2-CONNECT-PUTTY

    Step 4: Copy public IP address from ec2 instance.


    AWS-EC2-CONNECT-PUTTY

    Step 5: Select session in PuTTY, paste public IP address inside Host Name (or IP Address) text field. Port Number should be 22. The SSH check box should be checked. Then click on the Open button.


    AWS-EC2-CONNECT-PUTTY

    Step 6: Then give ec2 instance user name. Here current ec2 instance user name is “ec2-user”. Then press Enter key.


    AWS-EC2-CONNECT-PUTTY

    Step 7: Now ec2 instance is connected.


    AWS-EC2-CONNECT-PUTTY

  • Using WinSCP to connect EC2 instance
  • Step 1: Download and install WinSCP in your system if it is not already installed in the system.


    Step 2: Open WinSCP. Then click on the Advanced… button.


    AWS-EC2-CONNECT-WINSCP

    Step 3: Go to the left side path. Then Browse the .ppk file under the Private key file:


    AWS-EC2-CONNECT-WINSCP

    Step 4: Select the .ppk file in your system location. Then click on Open Button. Click on OK Button.


    AWS-EC2-CONNECT-WINSCP

    Step 5: Copy ec2 instance public IP address.


    AWS-EC2-CONNECT-WINSCP

    Step 6: Now put ec2 instance public IP address inside Host Name: Text Field. Ec2 instance user name inside User name: Text Field. 22 port number inside Port number. Click on Login Button.


    AWS-EC2-CONNECT-WINSCP

    Step 7: Now ec2 instance is connected.


    AWS-EC2-CONNECT-WINSCP

  • Using RDP client to connect EC2 instance
  • Step 1: Now I am using windows ec2 instance. Select ec2 instance. Click on Connect Button.


    AWS-EC2-CONNECT-RDP

    Step 2: Click on Get Password Button.


    AWS-EC2-CONNECT-RDP

    Step 3: Click on Choose File Button. Go to the .pem file location in your system and select the .pem file. Which is downloaded/ select at the time of launch Windows ec2 instance. Click on the Open button.


    AWS-EC2-CONNECT-RDP

    Step 4: Click on the Decrypt Password button.


    AWS-EC2-CONNECT-RDP

    Step 5: Now you can see the password on the below screen. Copy Password. Click on the Download Remote Desktop File button.


    AWS-EC2-CONNECT-RDP

    Step 6: Click on the downloaded file. Then click on Connect Button. Paste here copied password. Click on the OK button. Click on the Yes button.


    AWS-EC2-CONNECT-RDP

    Step 7: Now windows ec2 instance is connected.


    AWS-EC2-CONNECT-RDP

How to assign Elastic IP to EC2 instance?

Step 1: In the below screen you can see selected ec2 instance is not associated with Elastic IPs.


ASSIGN-ELASTIC-IP-EC2

Step 2: Go to the Elastic IPs tab. Click on Allocate new address button.


ASSIGN-ELASTIC-IP-EC2

Step 3: I am selecting the Amazon Pool scope. Click on Allocate Button.


ASSIGN-ELASTIC-IP-EC2

Step 4: Click on the Close button.


ASSIGN-ELASTIC-IP-EC2

Step 5: Click on the Actions button. Click on the Associate Address button.


ASSIGN-ELASTIC-IP-EC2

Step 6: Select ec2 instance. Click on the Associate button.


ASSIGN-ELASTIC-IP-EC2

Step 7: Now you will see a success message. Click on the Close button.


ASSIGN-ELASTIC-IP-EC2

Step 8: Now elastic IP address associated to ec2 instance. Click on Instance Id.


ASSIGN-ELASTIC-IP-EC2

Step 9: Now you can see elastic IP is associated with IPv4 Public IP address.


ASSIGN-ELASTIC-IP-EC2

How to deregister Elastic IP?

Step 1: Go to the Elastic IPs tab. Click on the Actions button -> Disassociate Address button.


DEREGISTER-ELASTIC-IP

Step 2: Click on Disassociate address button.


DEREGISTER-ELASTIC-IP

Step 3: Now elastic IP, disassociate from ec2 instance. You can see the below screen.


DEREGISTER-ELASTIC-IP

Step 4: Now finally Release elastic IP address. Go to the Elastic IPs tab. Click on the Actions button -> Click the Release addresses button.


DEREGISTER-ELASTIC-IP

Step 5: Click on the Release button.


DEREGISTER-ELASTIC-IP

Step 6: Now elastic IP address Release successfully also, removed from showing list.


DEREGISTER-ELASTIC-IP

How to solve .pem file bad permissions issue?

If you face the below issue while connecting ec2 instance using Windows System then the below steps need to follow:


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 1: Go to the pem file location -> Right click on pem file -> Click on Properties button -> Click Security Button -> Click on Advanced Button


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 2: Click on Add Button.


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 3: Click on the Select a principal button.


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 4: Inside Enter the object name to select, text field type “Administrator”. Click the Check Names button. Click on the Advanced… button.


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 5: Click on Find Now button. Select your system user. Click the OK button.


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 6: Now you can see the object name to select text field value, changed with your user name. Click on OK Button.


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 7: Basic permissions Options. Check Full control. Click on the OK button.


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 8: Click on Disable inheritance button. Click on Remove all inherited permissions from this object.


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 9: Click on Apply -> Click on the OK button.


AWS-EC2-CONNECT-COMMAND-PROMPT

Step 10: Click on the OK button.


AWS-EC2-CONNECT-COMMAND-PROMPT

How to generate .ppk file from .pem file?

Step 1: Download and install PuTTYgen in your system. If it is not already installed in your system.


Step 2: Open PuTTYgen. Then click on Load Button.


AWS-EC2-CONNECT-PUTTY

Step 3: Then select the .pem file. Click on the Open button.


AWS-EC2-CONNECT-PUTTY

Step 4: Click on the OK button.


AWS-EC2-CONNECT-PUTTY

Step 5: Then click on Save private key button. Then click on the yes button


AWS-EC2-CONNECT-PUTTY

Step 6: Give file name. Then click on the Save button.


AWS-EC2-CONNECT-PUTTY

Step 7: Now .ppk file is available in your system.


How to upload a file from the local machine to the EC2 instance?

Syntex: scp -i Pem_File_Location Upload_File_Location EC2_USER@Public_IPv4_DNS : Destination_File_Location

Example: To upload a single file. Use the below command. Here I am going to upload only 1.txt file.

AWS-EC2-UPLOAD-FILE

Example: To upload multiple files. Use the below command. Here I am going to upload all .txt extension files.

AWS-EC2-UPLOAD-FILE

Example: To upload multiple files. Use the below command. Here I am going to upload all types of extension files (.txt, .docx etc).

AWS-EC2-UPLOAD-FILE


How to download a file from the EC2 instance to the local machine?

Syntex: scp -i Pem_File_Location EC2_USER@Public_IPv4_DNS : Source_File_Location Destination_File_Location

Example: To download a single file. Use the below command. Here I am going to download only 1.txt file.

AWS-EC2-DOWNLOAD-FILE

Example: To download multiple files. Use the below command. Here I am going to download all .txt extension files.

AWS-EC2-DOWNLOAD-FILE

Example: To download multiple files. Use the below command. Here I am going to download all types of extension files (.txt, .docx etc).

AWS-EC2-DOWNLOAD-FILE


Important Points:

1. This post showing the screenshot view may be different at the time of practical. If you follow the concept then definitely you will get the desired output.

2. If you are not using EC2 Instance then you should stop EC2 instance. Stopped ec2 instance will not charge you.

3. If there is an elastic IP address that is not associated with running the ec2 instance. Release it otherwise it will charge.

4. While launching EC2 instance, instance type selection should be based on requirement type.