AWS CLI Contd
- Creating EC2 instance using AWS CLI.
- To create an ec2 instance we have the command run-instances Refer Here
- Ubuntu EC2 instance
- Make a note of AMI id of ubuntu 20 => ami-03d5c68bab01f3496
- Make a note of instance type => t2.micro
- Make a note of security group name and id => (sg-0eb0f3fca6c9a45a8
openall)
- Make a note of key pair => ansible
- Lets try to create ubuntu ec2 instance
aws ec2 run-instances --image-id 'ami-03d5c68bab01f3496' \
--instance-type 't2.micro' --key-name 'ansible' \
--security-group-ids 'sg-0eb0f3fca6c9a45a8'
- Lets try to stop the instance
aws ec2 stop-instances --instance-ids i-05025418f5dbd5d9e
- Now lets try to terminate the ec2 instance
aws ec2 terminate-instances --instance-ids i-05025418f5dbd5d9e
Exercise using AWS CLI
- Create two ubuntu ec2 instances with t2.micro instance type
- Try login in to both instances and install any software such as apache or nginx
sudo apt update
sudo apt install apache2 -y
- Stop one ec2 instance and modify the instance type to t2.nano
- Terminate all the two ec2 instances
aws ec2 run-instances --image-id 'ami-03d5c68bab01f3496' --instance-type 't2.micro' --key-name 'ansible' --security-group-ids 'sg-0eb0f3fca6c9a45a8' --count 2
aws ec2 describe-instances --filter 'Name=instance-state-name, Values=running'
aws ec2 stop-instances --instance-ids i-051287cbe1819817f
aws ec2 describe-instances --filter 'Name=instance-state-name, Values=running'
aws ec2 stop-instances --instance-ids i-0c8d896941e95dea2
aws ec2 modify-instance-attribute --instance-id i-0c8d896941e95dea2 --instance-type "{\"Value\": \"t2.micro\"}"
aws ec2 start-instances --instance-ids i-0c8d896941e95dea2
aws ec2 describe-instance --instance-id i-0c8d896941e95dea2
aws ec2 describe-instances --instance-id i-0c8d896941e95dea2
aws ec2 stop-instances --instance-ids i-0c8d896941e95dea2
aws ec2 modify-instance-attribute --instance-id i-0c8d896941e95dea2 --instance-type "{\"Value\": \"t2.nano\"}"
aws ec2 terminate-instances --instance-ids i-0c8d896941e95dea2
aws ec2 terminate-instances --instance-ids i-051287cbe1819817f
- Create one windows ec2 instance with t2.mico.
- Login into windows ec2 instance and install IIS Server.
- Launch Powershell as admin and execute
Install-WindowsFeature -name Web-Server -IncludeManagementTools