AWS Notes
AWS Notes
AWS Introduction
======================
-> AWS started providing IT resources over internet from 2006 onwards
-> AWS providing Cloud Services based on 'Pay As You Go' model
======================
AWS Services Names
======================
IAM : Identity & Access Management (who can access which service in AWS)
Lambda : Serverless Computing (run the code without thinking about servers)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++
-> To use AWS provided cloud services we need to create one account in AWS
-> AWS will charge 2 rs for account creation and they will send 2 rs back to our
account after account verified
-> In AWS few services are free and few services are paid
-> As part of our training we will use both free and paid services
Note: When we use paid services, after practise completion we need to delete those
service to avoid billing
-> If bill got generated we can request AWS Support team to waveoff our bill
because we are AWS learners and we are exploring AWS Cloud services.
-> AWS will not deduct bill amount from our card directley. We need to pay that
bill manually.
-> If we don't pay AWS bill amount then our AWS account will be terminated.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++
-> To provide Global Infrastructure AWS using Regions & Availability Zones concept
-> Data Center means a big building which contains servers with network
- ap-south-1a
- ap-south-1b
- ap-south-1c
Note: In AWS few services are global ( S3, Route 53 etc...) and few services
regional (EC2, VPC, RDS etc...)
========
EC2
========
-> The Virtual Machine which we create using EC2 service is called as EC2 instance
Note: EC2 providing t2.micro as free tier eligible for 1 year with monthly 750
hours
-> When we create EC2 instance, AWS will provide default storage and default
network
===================
EC2 instances types
===================
1) On-Demanded Instances
2) Reserved Instances
3) Spot Instances
4) Dedicated Host
====================
OnDemanded Instance
====================
-> No Committment
====================
Reserved Instances
===================
=================
Spot Instances
==================
-> AWS will offer high capacity systems for low price
=====================
Dedicated Host Instance
=====================
=====================
EC2 instance states
=====================
Stopped -- No Bill
Terminated -- No Bill
=====================
EC2 instance families
=====================
t2. t3, t4, c2, c3, i2, i3, m2, m3, m4 etc....
Note : t2.micro instances are Free for 1 year (from aws account creation date)
Note: Monthly 750 hours usage is free for 1 year when we go for t2.micro
Note: We can find EC2 instance types service rates in dashboard
===========================
Amazon Machine Image (AMI)
===========================
-> To create EC2 instance with Windows OS we can use Windows OS AMI
-> To create EC2 instance with Linux OS we can use Linux OS AMI
=======================
What is Key Pair in EC2 ?
=======================
-> Key Pair is the combination of Public Key and Private key
-> AWS will store public key and it will provide private key for us (We have to
save that very carefully)
-> Public key & Private Key is used to connect with EC2 instance securley
-> If we want to connect with EC2 VM we need to provide private key for AWS then
AWS will compare our private key with its public key. If both keys are matched
then only AWS will allow to login into EC2 VM.
-> Can i change key pair after EC2 VM creation ------> Not possible
==================
Security Groups
==================
-> Security Group is like a virtual firewall for our EC2 instance
-> Security Group will control Incoming and Outgoing traffic of our EC2 instances
Note: One security group we can use for Multiple Instances also
=============================
Creating Windows Virtual Machine
=============================
2) Launch instance
=> Once EC2 VM created then click on 'Connect' button and get below details
DNS : ec2-15-207-89-254.ap-south-1.compute.amazonaws.com
Username : Administrator
Password : rcAF2=D3s%g&%O98o?)*xUYd&!vdw?dp
====================================
Launching Linux Virtual Machine in AWS
==================================
2) Launch instance
=> Once EC2 VM created then click on 'Connect' button and get details
================
Instance States
===============
================
Types of IP's in AWS
=================
1) private ip
2) public ip
-> When we launch EC2 instance then AWS will provide one private ip and one public
ip for our instance
-> Private IP is a fixed IP and it is used by AWS for internal purpose. It will not
change when we re-start our EC2 instance.
-> Public IP is a dynamic IP. When we re-start our EC2 instance new Public IP will
be generated.
Note: To connect with EC2 instance from outside we will use Public IP.
-> Elastic IP means fixed public IP address.
-> We can create Elastic IP and we can associate that elastic ip for our EC2
instance
-> Elastic IP address will not change when we re-start our ec2 instance
Working process
+++++++++++++++
1) Create Elastic IP
2) Associate Elastic IP for EC2 instance
3) If we don't want to use elastic ip then De-Associate Elastic IP from EC2
instance
4) Release Elastic IP to AWS (Its mandatory)
================
Load Balancing
=================
-> If we deploy our application in one server then burden will increase on that
server
-> If burden increased on server then below are the problems we are going to face
5) Revenue Loss
6) Single point of failure (if server is down then application will be down)
-> To overcome all these problems we will run our application in Multiple Servers
-> The process of running our application in Multiple Servers is called as Load
Balancing.
-> To implement Load Balacing we will use Elastic Load Balancer (ELB) in AWS
-> LBR will recieve the request and it will distribute the requests to servers in
round robbin fashion
==============================
Types of Load Balancers in AWS
=============================
-> To implement load balancing for HTTP & HTTPS requests we will go for Application
Load Balancer (ALB)
-> By using Application Load Balancer we can implement Path Based Routing
==========================
Implemenging Load Balancer
===========================
#! /bin/bash
sudo su
yum install httpd -y
cd /var/www/html
echo "<html><h1>Welcome to Ashok IT :: Server 1</h1></html>" > index.html
service httpd start
#! /bin/bash
sudo su
yum install httpd -y
cd /var/www/html
echo "<html><h1>Welcome to Ashok IT :: Server 2</h1></html>" > index.html
service httpd start
#! /bin/bash
sudo su
yum install httpd -y
cd /var/www/html
echo "<html><h1>Welcome to Ashok IT :: Server 3</h1></html>" > index.html
service httpd start
Note: When request comes to Load Balancer it will distribute the requests to
servers which are part of given target group.
========================
Monolith Vs Microservices
=========================
1) Monolith Architecture
2) Microservices Architecture
-> Monolith Architecture means all the functionalities will be developed in single
project
-> A big war file will be created
-> Monolith Architecture based project is difficult to maintain
-> For any small change in the code then we have to re-deploy entire application
-> Single Point Of failure
Note: For Monolith app load balancing one target group will be created and
application will be deployed in all the servers who are belong that target group.
===================================
Microservices Based Load Balancing
===================================
=================================================
How to implement LBR for Microservices based application
=================================================
#! /bin/bash
sudo su
yum install httpd -y
cd /var/www/html
echo "<html><h1>Hotel Server - 1</h1></html>" > index.html
service httpd start
#! /bin/bash
sudo su
yum install httpd -y
cd /var/www/html
echo "<html><h1>Hotels Server - 2</h1></html>" > index.html
service httpd start
#! /bin/bash
sudo su
yum install httpd -y
cd /var/www/html
echo "<html><h1>Flights Server - 1</h1></html>" > index.html
service httpd start
#! /bin/bash
sudo su
yum install httpd -y
cd /var/www/html
echo "<html><h1>Flights Server - 2</h1></html>" > index.html
service httpd start
7) Goto LBR Listeners and configure Route Based Routing for Flights Target Group
================
Auto Scaling
=================
=> AWS Auto Scaling monitors your applications and automatically adjusts capacity
to maintain steady, predictable performance at the lowest possible cost.
=> Using AWS Auto Scaling, it’s easy to setup application scaling for multiple
resources across multiple services in minutes.
=> Amazon EC2 Auto Scaling helps you ensure that you have the correct number of
Amazon EC2 instances available to handle the load for your application.
=> The process of increasing and decreasing no.of ec2 instances based on the load
is called as Auto Scaling.
=============================
Advantages with Auto Scaling
=============================
2) Availability : Ensure that your application always has the right amount of
capacity to handle the current traffic demand.
3) Cost Management : Save money by dynamically launching instances when they are
needed and terminate them when they aren't needed.
=================================
How to setup Auto Scaling Group
=================================
###############################
Simple Storage Service (S3)
###############################
######### Amazon S3 : Object storage built to store & retrieve any amount of data
from anywhere ########
######### Note: 5 GB of S3 standard storage for 12 months with the AWS Free Tier
########
-> We can upload, download and access files from S3 at any point of time
-> We can't attach S3 to EC2 instance but we can access s3 buckets data from EC2
instance
-> S3 is serverless
-> In S3 we will store data in buckets. Bucket is a container & bucket contains
objects
object = file
key is name of the object
Note: always create a bucket with your company name or project name.
-> Max no.of buckets you can create in S3 is 100 (soft limit)
create bucket -> inside that create folder called photos -> inside that upload
puppy.jpg
Ex: http://8pmbukcet.s3.amazonaws.com/photos/puppy.jpg
=================================
Static Website Hosting using S3
=================================
1) Static Website
2) Dynamic Website
=> The website which will display same content/response for every user is called as
Static website.
=> The website which will display response based on user request is called as
Dynamic Website.
1) Create a bucket in S3
3) Go to Bucket Properties tab -> Enable Static Website hosting and configure index
and error pages
#############
Versioning
#############
-> When we upload same file multiple times then multiple versions will be created.
-> AWS charges for Versioning, becareful while you enable versioning for huge
files.
###############
Storage Classes
###############
-> While uploading the objects into S3 , selecting storage class is mandatory
Scenario : some customers wants to store and wants to access data frequently...
some other customers wants to store data but don't want to access frequently... we
can't charge same bill for both customers because they have diff businss
requirements.
-> To meet business requirements of clients, AWS provided several storage classes
in S3
------------------------------------------------
Standard Frequently Access( FA )
-----------------------------------------------
This is used for frequently access data
------------------------------------------------
Standard In-Frequently Access (IA)
-------------------------------------------------
Frequently access but not critical
Not Retrival charges
AWS doesn't recommend to use this
Cheaper than others
Availability = 99.9 %
Durability=99.99%
min obj size = 128 kb
min duration : 30 days
----------------------
One Zone IA
---------------------
In-frequently access but not critical
------------------------
Intelligent Tiering
------------------------
Unknown access pattern
Based on access it moves from FA to IA
availability=99.99%
Durability= 11 9's
------------
Glacier
-----------
Infrequently access data
archiving purpose
vault : container of archives
Archive : Object /Archive(zip) -> 40 TB
unlimited no.of archives
1000 vaults
Retrival charges apply
--------------------------------------
Glacier has retrival options
--------------------------------------
Expedited : 1 to 5 mins
Standard : 3 to 5 hours
Bulk : 5 to 12 hours
availability=99.99%
Durability= 11 9's
Min duration : 90 days
-> It is possible to move the objects from one storage class to another storage
class automatically (LCM) -> Life Cycle management.
-> my obj moving from FA -> IA (30 days) -> Glacier(60 days) ->this is called
transition
-> We can enable bucket logs to identify who is accessing our bucket
-----------------------
Encryption
---------------------
Encryption is used for security
Encryption can be done in 2 ways
serer-side encryption
SSE - S3 (AWS Managed Key)
SSE - KMS (AWS KMS Key)
SSE - C (Customer Provided Key)
##########################
Transfer Acceleration
##########################
-> If we want to transfer the data from our place to AWS S3 bucket it will use our
own internet.
-> It is used to transfer data fastly (It will use CDN concept) With CDN it will
use AWS internal network.
#################################
RDS (Relational Database Service)
#################################
3) Database
-> End users will communicate with our application using frontend (user interface).
-> When end-user perform some operation in the front-end then it will send request
to backend. Backend contains business logic of the application.
###########################################
Challenges with Database Setup on our own
###########################################
-> If we use AWS cloud, then AWS will take care of all the above works which are
required to setup Database for our application.
-> In AWS, we have RDS service to create and setup database required for our
applications.
-> We just need to pay the money and use Database using AWS RDS service. DB setup
and maintenence will be taken care by AWS people.
** Using RDS we can Easily set up, operate, and scale a relational database in the
cloud ***
######################################
Steps to create MYSQL DB using AWS RDS
######################################
4) Click on 'Create Database' (It will take few minutes of time to create)
###################
MySQL DB Properties
###################
Endpoint : database-1.cbair9bd9y7d.ap-south-1.rds.amazonaws.com
Uname : admin
Pwd : ashokitdevdb
Port : 3306 (it is default port for mysql db)
#############################
Steps to test MYSQL DB Setup
#############################
Link : https://aka.ms/vs/17/release/vc_redist.x64.exe
Link : https://dev.mysql.com/downloads/workbench/
4) Once we are able to connect with Database then we can execute below queries in
Workbench
###############
MySQL Queries
###############
show databases;
use sbidb;
show tables;
##########################################
Working with MySQL client in AMAZON Linux
##########################################
-u : It represents DB username
-p : It represents DB password
=> We can execute below queries to see the data which we have inserted previously
using Workbench.
show databases;
use sbidb;
show tables;
#################################
Spring Boot App with AWS RDS DB
#################################
URL : https://youtu.be/GSu1g9jvFhY
========================================
IAM (Identity & Access Management)
========================================
-> An AWS Identity and Access Management (IAM) user is an entity that you create in
AWS to represent the person or application that uses it to interact with AWS
Services.
-> AWS Identity and Access Management (IAM) is a web service that helps you
securely control access to AWS resources.
We can use IAM to control who is authenticated (signed in) and authorized (has
permissions) to use resources.
-> Best practice of using the root user only to create your first IAM user.
===============
Best Practices:
===============
- When we login AWS using 'email' and 'password', that has complete access to all
AWS services and resources in the account (Root account).
- Strongly recommended that you do not use the "root user" for your everyday tasks,
even the administrative ones.
- Instead, adhere to the best practice of using the root user only to create your
first IAM user. Then securely lock away the root user credentials and use them to
perform only a few account and service management tasks.
- IAM user is truely global, i.e, once IAM user is created it can be accessible in
all the regions in AWS.
- Amazon S3 also considered as Global but, it is not truely global. When we create
a bucket in S3
it displays all the buckets of other regions in one place , so that is the reason
we are calling AmazonS3 is Global (but partly global).
- But IAM is 100% Global. Once you create IAM user you can use it anywhere in all
the regions.
3. In MNCs , permissions will not be provided for individual users. Create the
Groups and add the users into it.
Users & Groups are for the Endusers.
Roles are for the AWS Services.
Steps:
====
1. Create an IAM user
Services - Security, Identity, & Compliance - IAM
Users---<Add user>
User name* = Iamuser1
Access type = 'select' both "Programmatic Access"
"AWS Management Console access"
click <NextPermissions>
(Note: we are not providing any permissions as of now, just <create user>)
(Note: Once you close this window, AccessKeyID and Secret Accesskey has gone,
so save it somewhere)
2. Group
<create new group>
Groupname =admins
(Note: no need add any policy now).
<creategroup>
GroupARN =arn:aws:iam::540105522204:group/admins
-Always add the permissions to the 'Groups' level not to the 'users' level. Its
a Best Practice in the real-time.
*****************
Policies:
*****************
- When we want to add the permissions to the the groups is through the 'Policies'.
- Default AWS Policies are appear in'Orange color Icons'
- One disadvantage of AWS Default Policies are , we can't customize the policies
to apply to the Groups.
- To provide customized policies to apply to Groups, we need to create the new one
and apply to the Groups.
https://4234324234.signin.aws.amazon.com/console
After Customize
https://classroomuser.signin.aws.amazon.com/console
IAMuser =Iamuser1
password=test1234
=================
Requirement:
=================
I got an requirement to create a new user and he should be able to do only 'stop'
and 'start' , 'reboot' select instances only.
He should not have the permissions to create the new EC2 Instance.
Open browser
https://classroomuser.signin.aws.amazon.com/console
login with Iamuser2 credentials
Services ---EC2
you will get an 'Authorization Error'
4. To view EC2 instances need to provide read permission to the user 'Iamuser2'.
- using Tags, we can provide permissions to this user.
5. Using this we can restrict the user to create EC2 instances. We can allow him to
do only 'stop' and 'start' Instances.
For this, need to write the custom scripts.
Open the browser search for ='restrict aws user ec2 instance'
https://aws.amazon.com/premiumsupport/knowledge-center/restrict-ec2-iam/
copy the script and open in any editor and customize it.
arn:aws:ec2:us-east-1:111122223333:instance/*"
(Note: For every service we have arn (amazon resource name), but for EC2
there is no arn naming)
InterviewQuestion:If anyone ask you , arn is not displaying for the EC2
instances?
Ans:Simply say that, ARN is not visible for the EC2 instances, but for the
other services like S3, we have ARN url.
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:StartInstances",
"ec2:StopInstances",
"ec2:RebootInstances"
],
"Condition": {
"StringEquals": {
"ec2:ResourceTag/Owner": "Bob"
}
},
"Resource": [
"arn:aws:ec2:us-east-1:111122223333:instance/*"
],
"Effect": "Allow"
},
{
"Effect": "Allow",
"Action": "ec2:Describe*",
"Resource": "*"
}
]
}
After Customization
===================
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:StartInstances",
"ec2:StopInstances",
"ec2:RebootInstances"
],
"Condition": {
"StringEquals": {
"ec2:ResourceTag/user": "Iamuser2"
}
},
"Resource": [
"arn:aws:ec2:us-east-1:449938344550:instance/*"
],
"Effect": "Allow"
},
{
"Effect": "Allow",
"Action": "ec2:Describe*",
"Resource": "*"
}
]
}
=============
Note:
449938344550 = Root AccountID
<ReviewPolicy>
7. Review Policy
Name ='UserRestrictEC2Instance'
<createpolicy>
-----------------------------------------------------------
What is IAM ?
What is Root Account ?
How to enable MFA for root account
--------------------------------------------------