Introduction To Amazon Ec2
Introduction To Amazon Ec2
Overview
In this exercise, we will initialize and learn the basic features of Amazon EC2. Then we
will connect and install a sample application called AWS User Management a simple
Nodejs CRUD application that allows user management (add, delete, edit, search) and
sharing to all other users. AWS User Management will be deployed on both Windows
and Linux.
The instructions in the article have been tested on Microsoft Windows Server
2022 and Amazon Linux 2.
Amazon EC2 is like a traditional physical or virtual server. EC2 has fast initialization,
strong resource scalability, and flexibility.
Virtual server: splits the physical server into many virtual servers, the purpose is to
make better use of resources.
Amazon EC2 can support workloads like web hosting, applications, databases,
authentication services, and anything else that a regular server can handle.
Configuration of Amazon EC2 is not optional, but configuration choice through selection
of EC2 Instance types.
Using AMI (Amazon Machine Image) can provision one or more EC2
Instances at the same time.
AMI available from AWS, on AWS Market Place and custom AMI created
from EC2 Instances.
AMI includes root OS volumes, AMI usage rights specify the AWS account to
be used, and mapping EBS volumes will be created and assigned to EC2
Instances.
EC2 instance can be backup by creating snapshot.
Key pair (public key and private key) used to encrypt login information for EC2
Instance
Preparation steps
In this lab, we use Microsoft Windows Server 2022 and Amazon Linux. We need to
prepare VPC and Security Group for both instances.
3. Configure Inbound rule: add seven Inbound rules by clicking Add rule and
creating as shown in the image below.
o SSH, port 22 to connect via PuTTY.
o All ICMP-IPv4
o All ICMP-IPv6
o HTTP, port 80
o HTTPS, port 443
o MySQL/Aurora, port 3306 used for Database MySQL.
o Custom TCP, port 5000 to run Nodejs application
1. Configure Outbound rules
o The tag section fills in the key and value
o Select Create security group
Create Security Group for Windows Instance
2. Configure Inbound rules: add eight Inbound rules by clicking Add rule and
creating as shown in the image below.
o SSH, port 22
o HTTP, port 80
o HTTPS, port 443
o RDP, port 3389 for connection
o All ICMP-IPv4
o All ICMP-IPv6
o Custom TCP, port 5000 to run Nodejs app
o MYSQL/Aurora, port 3306 for Database MySQL
3. Configure Outbound rules
o In the tag section, enter the key and value
o Select Create security group
LAUNCH WINDOWS INSTANCE
Launch Microsoft Windows Server 2022 instance
Initialize Microsoft Windows Server 2022 instance
This exercise provides an overview of working with Amazon EC2 objects and related
components. We will focus on basic tasks such as changing the configuration, creating
snapshots, building custom AMI, and accessing when key pair is lost.
Overview
Configuration of Amazon EC2 is not optional, but configuration choice through
selection of EC2 Instance types.
Content
Select Actions
Select Instance settings
Select Change instance type
3. In the Change instance type interface
o Change the type from t2.micro to t3.medium
o Instance type, select t3.medium
o Select Apply
o Find EC2
o Select EC2
o In the EC2 interface, select Snapshot
o Select Create snapshot
o Find EC2
o Select EC2
o Select Instances
o Select Windows-instance
o Select Actions
o Select Image and templates
Key Pair is used to encrypt and decrypt credentials to the EC2 virtual server.
In case of losing key pair, we can perform the following steps to assign a new key pair.
Select AMIs
o
Select Custom Windows AMI just created from Microsoft Windows Server
o
2022 instance
o Select Launch instance from AMI
2. Name: enter Windows Server AMI
3. In the AMI selector
o Select AMI from catalog
4. Next, select Instance type and select Create new key pair
5. In the Create key pair interface
o Key pair name, enter kp-windows2
o Private key file format, select .pem
o Select Create key pair
6. Then we configure the network for the new instance. In Network settings,
select Edit and then:
o VPC: select Windows-vpc
o Subnet: select public subnet
o Auto-assign public IP: select Enable
o Firewall (security group): select Select existing security group
o Common security groups: select Windows-SG
7. Finish creating a new instance, and select View all instance to see details about
the instance
ACCESSING EC2-WINDOWS KEY PAIR
LOSS USING SSM
We will solve the problem of losing the access key pair
Key Pair is used to encrypt and decrypt credentials to the EC2 virtual server.
In case of losing key pair we can perform the following steps to reset key
pair using AWS Systems Manager service.
Request:
1.In order for AWS Systems Manager to perform tasks on EC2, it is necessary
to check the status of SSM agent , in the EC2 interface
Select Instances
Select connect
1.1 If SSM agent is active & authorized, the Session Manager section will
bold Connect (Continue to step 2), if not, perform the assignment * role* (with SSM
permissions) on EC2.
1.2 Assign roles - have SSM permissions for EC2, In the IAM interface
Select Roles
1.5 Next,
Select Instances
Select EC2 Windows-instance
Select Actions -> Security -> Modify IAM role
In the IAM role section, select the role you just created: Windows-instance
Select Update IAM role
In this lab, installing LAMP web server makes use of MySQL database, in addition to
installing LAMP Web Server, you can use it to host *WordPress website *
Use the yum install command to install multiple software packages and all
related dependencies at once.
Select Instances
Select Linux-instance
Copy Public IPv4 address
7. Paste Public IPv4 address into your browser to test Apache
o Use IP Public
Use DNS
To add group write permissions and set group IDs on future subdirectories,
change the directory permissions of /var/www and its subdirectories.
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
To add group write permissions, recursively change the permissions for the
file /var/www and its subdirectories:
rm /var/www/html/phpinfo.php
CONFIGURING THE DATABASE SERVER
Database server security configuration
The mysql_secure_installation command will guide you through the process of setting
a root password and removing unsafe features from your installation.
2. Run mysql_secure_installation
sudo mysql_secure_installation
INSTALLING PHPMYADMIN
Install phpMyAdmin
phpMyAdmin is a web-based database management tool that you can use to view and
edit MySQL databases on your EC2 instances. Follow the steps below to install and
configure phpMyAdmin on your Amazon Linux instance.
3. Restart php-fpm.
cd /var/www/html
5. Download phpMyAdmin
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-
languages.tar.gz
rm phpMyAdmin-latest-all-languages.tar.gz
http://ec2-54-255-148-96.ap-southeast-1.compute.amazonaws.com/
phpMyAdmin/
You will see the phpMyAdmin login page.
Proceed to login with user name: root and password: 123Admin
Select Login
) ENGINE = InnoDB;
In the lab, we use Node.js with the SDK for JavaScript to set up and run the Node.js
web application on Amazon Elastic Compute Cloud (Amazon EC2).
You must configure Security Group to allow SSH (port 22), HTTP (port 80), HTTPS
(port 443) and app using Nodejs (port 5000)
1. Install node version manager (nvm) ) by typing the following in the following command
line:
Note: We will use nvm to install Node.js because nvm can install multiple versions of
Node.js and allows you to switch between them.
2. Enable nvm by typing the following in the command line:
. ~/.nvm/nvm.sh
3. Use nvm to install the latest version of Node.js by typing the following in the
command line.
nvm install 16
node –v
npm –v
1. We use git to clone the source code. First of all, install git with the following command:
git version
cd ~ec2-user
cd 000004-EC2
ls
5. NPM stands for Node package manager and is a tool to create and manage
Javascript programming libraries for Node.js. Using npm init to initialize the
project will generate a sample package.json file.
npm init
NOTE : You proceed to configure the application’s information and it is saved in the
file package.json
6. Next we do dependencies installation
express
Dotenv
express-handlebars
body-parser
mysql
touch .env
9. Use vi to edit the .env file. We perform the database configuration:
DB_HOST = 'localhost'
DB_NAME = ‘awsuser'
DB_USER = 'root'
DB_PASS = '123Admin'
11. Restart Express server. Use Nodemon to save time
npm start
Select Instances
Select Linux-instance
Copy Public IPv4 DNS address
14. Paste Public DNS IPv4 address into the browser and port 5000. Observe
the AWS FCJ Management interface
Select Format
Select Go
22. The interface of the instance when starting the local server