Table of contents
Virtual Machines (VMs) are a fundamental component of modern-day computing. VMs provide a convenient way to test software applications, isolate operating systems, and provide a flexible and cost-effective solution for hosting applications. In this blog post, we'll explore how to login to your VM and different ways to automate the creation of VMs.
📍 Ways to Connect to EC2 Instance
How to Login to Our VM Connecting to your VM can be done in two ways - through a web browser or through SSH. Here are the steps for both methods:
🔹 Connect using Browser
Log in to the AWS Management Console.
Navigate to the EC2 dashboard.
Locate the instance that you want to connect to.
Click on the "Connect" button.
In the "Connect To Your Instance" window, select "EC2 Instance Connect" and click on "Connect".
A new browser window will open, and you will be automatically logged in to your instance.
Connect using SSH SSH (Secure Shell) is a widely used protocol for secure remote access. Here are the steps for connecting to your instance using SSH:
🔹 Putty & Putty Gen
Download and install Putty and PuttyGen.
Generate an SSH key pair using PuttyGen.
Copy the public key to your instance using the AWS Management Console.
Launch Putty and enter the public DNS of your instance.
In the "Connection" tab, expand the "SSH" tab and click on "Auth".
In the "Authentication Parameters" section, browse and select your private key file.
Click on "Open" to connect to your instance.
🔹 CMD for Windows, Terminal in Linux, or iTerm Terminal for MacBook
Open your terminal application.
Change the permissions of your key pair by typing "chmod 400 myKeyPair.pem" (replace "myKeyPair.pem" with your own key pair name).
Connect to your instance by typing "ssh -i /path/to/myKeyPair.pem ec2-user@PublicDNS" (replace "myKeyPair.pem" and "PublicDNS" with your own key pair name and the public DNS of your instance, respectively).
🔹 MobaXterm (Platform Independent)
Download and install MobaXterm.
Launch MobaXterm and click on the "Session" button.
Enter the public DNS of your instance and select "SSH" as the session type.
In the "Advanced SSH settings" section, click on the "Use private key" checkbox and browse and select your private key file.
Click on "OK" to connect to your instance.
📍 Ways to Automate VM Creation
Different Ways to Automate the Creation of VM Automating the creation of VMs can save you time and effort, especially if you need to create many instances at once. Here are three ways to automate the creation of VMs:
🔹 AWS CLI
Steps to Create EC2 Instance Using AWS CLI The AWS CLI (Command Line Interface) is a powerful tool that allows you to manage your AWS resources from the command line. Here are the steps to create an EC2 instance using AWS CLI:
Download and install the AWS CLI.
Authenticate and authorize using your AWS access and secret key by typing "aws configure".
Create an EC2 instance by typing "aws ec2 run -instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name myKeyPair --security-group-ids sg-xxxxxxxx".
Note: Replace "ami-xxxxxxxx", "myKeyPair", and "sg-xxxxxxxx" with your own AMI ID, key pair name, and security group ID, respectively.
Wait for the instance to be created.
Use the "aws ec2 describe-instances" command to verify that the instance has been created.
🔹 AWS CloudFormation Templates:
Steps to Create Using CloudFormation Templates CloudFormation is a service that allows you to define your AWS infrastructure as code. Here are the steps to create an EC2 instance using a CloudFormation template:
Create a CloudFormation stack by navigating to the CloudFormation dashboard and clicking on "Create Stack".
Select "Template is ready" and "Upload a template file".
Choose a CloudFormation template from GitHub or upload one locally.
Follow the instructions on the screen to create the stack.
🔹 AWS API - Python Boto3:
Steps to Create Using AWS API - Python Boto3 Boto3 is the AWS SDK for Python, which allows you to write Python scripts to automate AWS tasks. Here are the steps to create an EC2 instance using Boto3:
Install Boto3 by typing "pip install boto3".
Import the Boto3 library into your Python script.
Authenticate and authorize using your AWS access and secret key.
Create an EC2 instance by calling the "run_instances" method of the EC2 client object.
Wait for the instance to be created.
Use the "describe_instances" method to verify that the instance has been created.
Beautiful Documentation of Boto3 Boto3 is a comprehensive Python library that allows you to interact with many AWS services. The Boto3 documentation is well-written and easy to navigate, with examples and code snippets for many AWS services. You can access the documentation at boto3.amazonaws.com/v1/documentation/api/la...
In this blog, we discussed two important topics related to AWS: how to log in to your VM and how to automate the creation of VMs. We covered different methods to log in to your VM, such as connecting using a browser or SSH, and discussed different tools like Putty, MobaXterm, and NoMachine. We also explained the steps to automate the creation of VMs using AWS CLI, CloudFormation templates, and Python Boto3.
By mastering these skills, you can save time and effort and increase your productivity when working with AWS. Whether you are a developer, system administrator, or business owner, knowing how to log in to your VM and automate the creation of VMs can help you achieve your goals faster and more efficiently. So, start practising these techniques today and take your AWS skills to the next level!