AWS EC2 contd…
Activity 3
- Create an ec2 instance with
- ubuntu 20.04 AMI
- imported key pair
- 22 and 80 port open to all
- instance type: t2.micro
- Install webserver => Apache with php
sudo apt update
sudo apt install apache2 stress -y
sudo apt install php libapache2-mod-php php-mysql -y
echo '<?php phpinfo(); ?>' > info.php
sudo cp info.php /var/www/html/info.php
- Solution 1: Create ec2 instance with above options. SSH into EC2 and execute the commands
- SSH and execute the following commands
- Now navigate to
http://<publicip>/info.php
- SSH and execute the following commands
- Solution 2: User Data
- Open Advanced details while creating ec2 instance and navigate to the user data section
- Now launch ec2 instance
- Now navigate to
http://<publicip>/info.php
- Userdata is the script that will be executed as a root user by your aws instance.
- This script gets execute only while creating the ec2 instance.
- Lets verify the logs
- Open Advanced details while creating ec2 instance and navigate to the user data section
- Refer Here for cloud-init.
AWS EC2 instance Lifecycle
- The billing part of the ec2 instance will be applicable only for on-demand instances.
- Refer the below image for instance states
- Refer Here for the offical docs on instance lifecycle.
- Actions that can be performed on ec2
- launch => Create an ec2 instance
- stop => stop the ec2 instance which is running
- start => start the ec2 instance which is stopped
- terminate => terminate the running or stopped ec2 instance
- stop-hibernate => hibernate the ec2 instance which is running