Search This Blog

Sunday, December 25, 2016

Part-13-AWS-Network-VPC

VPC (Virtual Private Cloud)








·        Logically isolated AWS resource
·        Can be securely integrated with internal systems via a VPN
·        AWS is now defaulting to using VPC for EC2 instances
o   Older accounts can still launch into "EC2 classic"
Ø  Ability to simulate a private cloud within the public AWS infrastructure
o   Utilize AWS resources in an isolated virtual network
o   Provides complete control of the virtual network
§  IP address range, subnets, route tables, gateways, access control, etc.
§  Can control both inbound and outbound network traffic
Ø  No costs for using a VPC
o   Just pay for resources used
o   There is additional hourly charge for a VPN connection
Ø  As discussed earlier, EC2 is now requiring all instances in a VPC
Ø  Additionally, you can create a Hardware Virtual Private Network (VPN) connection between your corporate datacenter and your VPC and leverage the AWS cloud as an extension of your corporate datacenter.

Hardware Tenancy

Ø  Can specify hardware tenancy
o   Default is multitenant
§  Hardware is potentially shared with many customers
o   Dedicated
§  Hardware is dedicated for instances running in your VPC
§  Additional fees apply
o   Host
§  Your instance runs on a Dedicated Host, which is an isolated server with configurations that you can control.
Ø  You cannot change the tenancy of a default instance after you've launched it. You can change the tenancy of an instance from dedicated to host after you've launched it, and vice versa. 

What can you do with a VPC?

·        Launch instances into a subnet of your choosing
·        Assign custom IP address ranges in each subnet
·        Configure route tables between subnets
·        Create internet gateways and attach them to subnets (or not)
·        Much better security control over your AWS resources
·        Instance security groups
·        Subnet network access control lists (ACLS)

Default VPC vs Custom VPC

·        Default VPC is user friendly, allowing you to immediately deploy instances.
·        All subnet in default VPC have an internet gateway attached.
·        Each EC2 instance has both a public and private IP address.
·        If you delete the default VPC the only way to get it back is to contact AWS.

VPC Peering

·        Allows you to connect one VPC with another via a direct network route using private IP addresses.
·        Instances behave as if they were on the same private network
·        You can peer PVC’s with other AWS accounts as well as with other VPCs in the same account.
·        Peering is in a star configuration, i.e. 1 Central VPC peers with 4 other. No Transitive Peering!!!





VPC Peering is simply a connection between two VPCs that enables you to route traffic between them using private IP addresses. Instances in either VPC can communicate with each other as if they within the same network. You can create a VPC peering connection between your own VPCs, or with a VPC in another AWS account within a single region.
AWS uses the existing infrastructure of a VPC to create a VPC peering connection; it is neither a gateway nor a VPN connection, and does not rely on a separated piece of physical hardware. There is no single point of failure for communication or a bandwidth bottleneck.



·        You cannot create a VPC peering connection between VPCs that have matching or overlapping CIDR blocks.
·        You cannot create a VPC peering connection between VPCs in different regions.
·        VPC peering does not support transitive peering relationship.

Multiple VPC Configurations


VPC with a Single Public Subnet Only

Ø  Used for servers that need to be accessed over the public Internet
o   Least private option
o   We have already used this during the class



VPC with Public and Private Subnets

Ø  Used when some servers need to be accessed over the Internet while other servers need to be kept private
o   Servers on the public subnet can be accessed from the Internet
o   Servers on the private subnet cannot be accessed from Internet
§  If needed, servers on private subnet can connect outbound to the Internet on the public subnet using Network Address Translation (NAT)



VPC with Public and Private Subnets, Hardware VPN Access

Ø  Used when some servers need to be accessed over the Internet while other servers need to be kept private
o   Servers on the public subnet can be accessed from the Internet
o   Servers on the private subnet can only be accessed over a hardware VPN connection
o   Used to extend your private data center into the cloud
o   Hardware VPN connection will make the VPC servers appear to be on your local private network


VPC with Private Subnet Only and Hardware VPN Access

Ø  Used to extend your private data center into the cloud
o   Can only access VPC resources from behind your private VPN firewall
o   Most private option
§  A hosted private cloud


Common Uses

Ø  VPC with a single public subnet only
o   Public-facing website
Ø  VPC with public and private subnets
o   Multitiered public-facing website
§  Web server in the publicly accessible subnet
§  Database and application servers in private subnet
Ø  VPC with public and private subnets and hardware VPN access
o   Web applications that require access to your internal data center
§  Public-facing web server running in AWS requires ability to access resources within your data center
Ø  VPC with a private subnet only and hardware VPN access
o   Seamlessly extend your data center to gain capacity required
o   Can use for disaster recovery
§  Utilize VPC to host redundant systems and data
§  A fraction of the cost of traditional disaster-recovery options

Configuring VPC

1. Create VPC


Log in to the AWS console.
Navigate to Services->VPC->Your VPCs.
Click “Create VPC”.
When you create a VPC, you specify a set of IP addresses in the form of a Classless Inter-Domain Routing (CIDR) block (for example, 10.0.0.0/16). For more information about CIDR notation and what "/16" means, see Classless Inter-Domain Routing.
You can assign a single CIDR block to a VPC. The allowed block size is between a /28 netmask and /16 netmask. In other words, the VPC can contain from 16 to 65,536 IP addresses.
You cannot change a VPC’s size after creating it. If your VPC is too small for your needs, you’ll need to terminate all of the instances in the VPC, delete it, and then create a new, larger VPC.
To create your VPC, go to the Create VPC dialog box, specify the following VPC details and then click “Yes, Create”.
CIDR Block: Specify the CIDR block for your VPC. I prefer 10.0.0.0/16.
Tenancy: Default tenancy: This is for running instances on shared hardware and is free of charge.
Dedicated Tenancy: This is for running your instances on single-tenant hardware. A $2 fee applies for each hour in which any dedicated instance is running in a region.



2. Create Subnets

In the navigation pane click on “Subnets”.
Click “Create Subnet”.
Before we create a subnet, let’s understand the best practices for creating them.
You should create subnets across multiple availability zones, with each subnet residing within a single zone. Creating subnets in and launching instances across multiple availability zones will ensure a high-availability environment.
For this example, we created subnets using zones us-east1a, user-east1b and us-east-1c. These subnets are called “private subnets” because the instances we launch are not accessible from the Internet. In other words, these instances don’t have a public IP unless you assign an EIP.
EC2: 10.0.1.0/24 (us-east1a), 10.0.2.0/24 (us-east1b), 10.0.3.0/24 (us-east1c)





3. Create Internet Gateway

By default, instances that are launched into a VPC can't communicate with the Internet. However, you can enable Internet access by attaching an Internet gateway to the VPC.
Go to Internet Gateways in the navigation pane and click “Create Internet Gateway”.





Now attach the gateway to a VPC by right clicking on “VPC” and selecting “Attach to VPC”. We should have one Internet Gateway per VPC.


4. Create Route Tables

A route table contains a set of rules, called routes that determine where network traffic is directed.
Each subnet in your VPC must be associated with a route table that will control that subnet’s routing. You can associate multiple subnets with a single route table; however, you can only associate a subnet with one route table.
Creating a VPC automatically creates a main route table which, by default, enables the instances in your VPC to communicate with one other.
Go to Route Tables in the navigation pane and click on “Create Route Table”.



Do not associate any subnets with the main route table.
Now navigate to the main route table to add a route to allow Internet traffic to the VPC.
Go to Routes and specify the following values:
Destination: 0.0.0.0/0
Target: Select “Internet Gateway” from the dropdown menu.


As a best practice create separate route tables for each tier. This will provide more control in maintaining the security of each subnet.
Now associate the subnets to the route tables.
Click on one route table and go to the Associations tab.
Select the subnet and click “Associate”.



 Here we had associate Subnet 10.0.1.0/24 as internet facing.

 5. Create an EC2 instance now.

So Subnet 10.0.1.0/24 will be our webserver which will have internet facing.
Subnet 10.0.2.0.24 will be our Database server which will not have internet connectivity.
We will create an EC2 instance in each subnet.
Creating EC2 instance for webserver in subnet 10.0.1.0/24
Step1: Choose an Amazon Machine Image(AMI) (Amazon Linux AMI 2016.03.3 (HVM), SSD Volume Type)
Step2: Choose an Instance Type (General Purpose t2 micro)
Step3: Configure Instance Details


Step4: Add Storage
Step5: Tag Instance (MyWebServer)
Step6: Configure Security Group
Create a new Security Group.



Step7: Review Instance Launch
Step8: Create an new key pair & Launch Instance.
Creating EC2 instance for Database Server in subnet 10.0.2.0/24
Step1: Choose an Amazon Machine Image(AMI) (Amazon Linux AMI 2016.03.3 (HVM), SSD Volume Type)
Step2: Choose an Instance Type (General Purpose t2 micro)
Step3: Configure Instance Details



Step4: Add Storage
Step5: Tag Instance (MyDBServer)
Step6: Configure Security Group
Select an existing SG MyVPCSG



Step7: Review Instance Launch
Step8: Create an new key pair & Launch Instance.
Now we could see that MyWebServer got PublicIP & MyDBserver do not have Public IP address. Now to test our setup, we will connect with putty to both the host, and try to check whether internet is working on which server.
I tried to connect to the host MyWebserver using Putty, and found that Internet is working on the host.
[root@ip-10-0-1-13 ~]# ping google.com
PING google.com (172.217.5.14) 56(84) bytes of data.
64 bytes from lga15s49-in-f14.1e100.net (172.217.5.14): icmp_seq=1 ttl=47 time=7.79 ms
64 bytes from lga15s49-in-f14.1e100.net (172.217.5.14): icmp_seq=2 ttl=47 time=7.89 ms
64 bytes from lga15s49-in-f14.1e100.net (172.217.5.14): icmp_seq=3 ttl=47 time=7.91 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 7.794/7.865/7.911/0.088 ms
[root@ip-10-0-1-13 ~]#
Now we will try to connect MyDB Server.
We are connecting to MyDBServer with Private IP address, as it has not having Public IP address
[root@ip-10-0-1-13 ~]# vi mynewkeypair.pem
[root@ip-10-0-1-13 ~]# chmod 600 mynewkeypair.pem
[root@ip-10-0-1-13 ~]# ssh ec2-user@10.0.2.181 -i mynewkeypair.pem
We could see that internet is not working on this server.
[ec2-user@ip-10-0-2-181 ~]$ ping google.com
PING google.com (172.217.1.78) 56(84) bytes of data.
^C
--- google.com ping statistics ---

8 packets transmitted, 0 received, 100% packet loss, time 7055ms

Part-12-AWS-Network-Elastic IP

Elastic IP Address

·        An elastic IP is a static IP assigned to your AWS account and can be
o   Associated with any running instance
o   Remapped to a different instance at any time
o   Leveraged with DNS to resolve your own hostname to this IP
·        New accounts are limited to five elastic IPs per region
·        Higher limits can be requested at http://aws.amazon.com/contact-us/eip_limit_request
§  Requests are for a specific region
·        Instances can be assigned multiple elastic IPs
o   Only when running within a VPC
·        No additional charge for an elastic IP if associated with a running instance
o   Only charged if you do not use it!
§  Hourly charge for elastic IPs allocated but not associated to any instance


o   Hourly charge for additional elastic IPs associated with a single instance

Saturday, December 10, 2016

Part - 11 - AWS - AWS ELB (Elastic Load Balancer)

AWS ELB (Elastic Load Balancer)

The Elastic Load Balancer or ELB is a web service that allows you to automatically distribute incoming traffic cross a fleet of EC2 instances. In simpler terms, an ELB acts as a single point of contact between your clients and the EC2 instances that are servicing them. The clients query your application via the ELB; thus, you can easily add and remove the underlying EC2 instances without having to worry about any of the traffic routing or load distributions. It is all taken care of by the ELB itself!
Exam Topics:
·        In Service or Out of Service
·        Health Checks
·        Have their own DNS name. You are never given an IP address.
Second important thing worth mentioning is the ELB’s costs. Although it is free (Terms and Conditions apply) to use under the Free Tier eligibility, ELBs are charged approximately $0.025 per hour used. There is a nominal charge on the data transferring as well, which is approximately $0.008 per GB of data processed.
·        Detects unhealthy instances and directs load to only healthy ones
·        Can distribute load across availability zones
·        Paid-for service
·        Can be used with Auto Scaling



·        An Elastic Load Balancer provides a DNS host name
o   The name clients should connect to
o   This IP address may change over time
o   Use a CNAME alias to use your own domain name to reference the ELB
§  Never use an “A” record!
·        ELBs are designed to be fault-tolerant
o   Only need to define a single ELB
o   One ELB can span multiple availability zones
·        ELBs support HTTPS
o   Can upload your own SSL certificate

Routing Request

Ø  ELB default is to route requests to the instance with the smallest load
o   The ELB keeps track of this
Ø  Can also configure ELB to persist sessions (called sticky sessions)
o   All requests from a single user will be routed to the same instance
o   Implemented with either
§  ELB-generated HTTP cookies
§  Application-generated HTTP cookies
Ø  Generally, sticky sessions should be avoided
o   Goes against many benefits of cloud computing
o   Assumes that a particular instance will be running



 Configuring a Load Balancer:

Ø  Can configure with any of the management tools
o   This section will use the Management Console
Ø  To configure a load balancer with the Management Console
o   From the EC2 service, click Load Balancers, then Create Load Balancer
o   Specify a name for the load balancer and which protocols/port numbers to load balance
Ø  Add at least two subnets to load balance
Ø  Click Next
Ø  Select a security group for the load balancer to use
Ø  Click Next
 



 


Ø  The next screen allows for custom health checks to be created, specifying
o   Protocol, port, and path to perform the check
§  Path is only for HTTP(S)
o   Time to wait for a response
o   How often to perform the check
o   Number of consecutive failures before marking down
Ø  Number of consecutive successes before marking healthy


Ø  Existing instances can be manually added to the load balancer when created
o   Just select them in the table of existing images
 



Ø  Once created, a load balancer constantly monitors instances
o   Ensures that they are all healthy and will only route traffic to healthy instances
 


  
 


Auto Scaling and Load Balancing

Ø  Auto Scaling and load balancing can be used together
o   New instances started by an Auto Scaling policy can be automatically registered with a load balancer
Ø  Enable by specifying an load balancer when creating or updating an Auto Scaling group
o   Can specify more than one load balancer

#aws autoscaling create-auto-scaling-group --auto-scaling-group-name user01ASGrp --launch-configuration-name user01LC --vpc-zone-identifier subnet-41767929c --minsize2 --max-size 4 --load-balancer-names <load_Bal-1> <load_Bal-2>...

ELB Limits

Ø  AWS accounts are initially limited to 10 load balancers
Ø  Higher limits can be requested at http://aws.amazon.com/contact-us/elb-request/
o   Requests are for a specific region

Exam Topics:

·        In Service or Out of Service
·        Health Checks

·        Have their own DNS name. You are never given an IP address.