Jun 24, 2018

Amazon SNS [Simple Notification Service] Using CLI

Amazon SNS

SNS [Amazon Simple Notification Service]:

SNS means Simple Notification Service. It provides robust messaging service for web applications.

It is a versatile messaging service which can deliver message to any devices also to send notification to different AWS resources.

SNS offers 'push' messaging service which is based on publisher subscriber model that means multiple publishing application can to communicate with multiple subscribing application using AWS SNS.

It supports multiple transport protocols that are Amazon SQS, Lambda, HTTP, HTTPS, Email, SMS and Mobile Notifications.

SNS Support Protocols


Following are the components of AWS SNS:

Topic:
It contains subject and content event each topic has unique identifier [ URI ]. URI identify the SNS endpoint to publishing and subscribing for messages related to particular topic.

Owners: 
They are the topic creators which defines the topics

Subscribers:
They are the belongs the client, end users, applications, services that wants to receives notification on specific topic. Single topic can have multiple subscribers.

Publishers:
They are the message or notification carriers they send message to topics and SNS matches the topic with list of subscribers interested in that topic and deliver message to each one. Publisher have rights to publish message on different topics

SNS Usage Emaple


Lets see...

How To Configure SNS Using AWS CLI:

First create a SNS topic using command below:

>> aws sns create-topic --name pg-topic

Output: 

"TopicArn": "arn:aws:sns:us-east-2:948488888:pg-topic"

Save this ARN for future reference or usage.

Now subscribe to this pg-topic topic:

>> aws sns subscribe --topic-arn EnterTopicARN --protocol email --notification-endpoint pranaydac08@gmail.com

Once we execute above command it will send confirmation email on that email ID and they need to confirm subscription by clicking on confirmation link then only publisher can send emails to subscriber.

Now publish topic and send email to subscriber:

>> aws sns publish --topic-arn EnterTopicARN --message "This is test message..."

This will send email to all subscribers who subscribed this "pg-topic" topic and you can also confirm this from AWS management console by clicking on menu SNS.


How To Unsubscribe Topic Using CLI:

>> aws sns unsubscribe --subscription-arn EnterSubscriptionARN

How To Delete AWS SNS Topic Using CLI:

>> aws sns delete-topic --topic-arn EnterTopicARN

We can get topic ARN by using command below:

>> aws sns list-topics

Please note in next session we will learn "How To Configure SQS Using AWS CLI"...

Happy Learning AWS Services!!!! :) Still Doubts? lets put your questions in below comment box! Thanks!

Watch Video:




Jun 17, 2018

AWS Internal Load Balancer Using CLI

AWS Internal Load Balancer Using CLI

The Classic Load Balancer & Application Load Balancer are the external load balancers which could be access by external client over Internet having public IP addresses hence external load balancer routes the request from client over Internet but some times we need to load balance internal services which are not accessible by external clients.

For Example: In AWS bunch of micro services which is only used by AWS Infrastructure internally so to balance the load of these internal services we can use Internal Load Balancer.

The Internal load balancer only have private IP address and therefore internal load balancer only route request from client which have VPC access.

For Example: If our application has multiple tiers like web server connected to Internet and Database server that only connected to Web server. So in this case we can create a Internal Load Balancer for Database Server. Web Server will receive request from External Load Balancer and send request to Database Server via Internal Load Balancer and DB Server receives request from Internal Load Balancer and will respond to Web Server.

Internal-Load-Balancer-Flow


Lets see...

How To Create Internal Load Balancer Using AWS CLI:

>> aws elb create-load-balancer --load-balancer-name pgelbinternal --listeners "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80" --scheme internal --subnets EnterSubnetsIds --security-groups EnterSecurityGroupID

To create internal load balancer we need to use following command and parameters:

Command : aws elb create-load-balancer

Parameters:

load-balancer-name : Load Balancer Name
listeners : Load balancer listener
scheme : In this parameter we need to pass value 'internal' because by default it will consider 'external' which means public internet facing load balancer.
subnets : Recommended Private Subnet Ids
security-group : Security group Ids

Output: It will show one DNS with prefix 'internal' like "internal-pgelbinternal-021252222.region.elb.amazonaws.com"

We can verify it from AWS management console by clicking on Load Balancer menu.

Lets see...

How To Register Instances With Internal Load Balancer:

>> aws elb register-instances-with-load-balancer --load-balancer-name pgelbinternal --instances EnterInstanceID

To register instance with internal load balancer we need to use following command and parameters:

Command: aws elb register-instances-with-load-balancer

Parameters:

load-balancer-name : Internal Load Balancer Name which we want to register with instance
instances : Instance Id which we want to register with Internal Load Balancer

We can verify it from AWS console by clicking 'Load Balancer' menu and click on "Instance" tab

How To De-register Instances From Internal Load Balancer:

>> aws elb deregister-instances-from-load-balancer --load-balancer-name pgelbinternal --instances EnterInstanceID

To de-register instance with internal load balancer we need to use following command and parameters:

Command: aws elb deregister-instances-from-load-balancer

Parameters:

load-balancer-name : Internal Load Balancer Name which we want to deregister from instance
instances : Instance Id which we want to deregister from Internal Load Balancer

We can verify it from AWS console by clicking 'Load Balancer' menu and click on "Instance" tab


How To Delete Internal / External Load Balancer Via AWS CLI:

>> aws elb delete-load-balancer --load-balancer-name pgelbinternal



Happy Learning AWS Services!!!! :) Still Doubts? lets put your questions in below comment box! Thanks!

Watch Video:

Jun 10, 2018

Create Classic Load Balancer Using AWS CLI [Part-2]

Classic Load Balancer Using AWS CLI

In last session we have seen how to create Application Load Balancer using "elbv2" command.

Classic Load Balancer is used to route traffic, based on applications or network level details.

It is best option for simple load balancing traffic across multiple EC2 instances where high availability, auto scaling and robust security are basic requirement of application.

It works under 4th layer of OSI model which is Transport Layer and supports TCP, SSL, HTTP, HTTPS protocols.

Classic Load Balancer supports command "aws elb" without v2 version operation where as in last session for Application Load Balancer we used command "aws elbv2".

>> aws elb create-load-balancer --load-balancer-name pgLoadBalClassic --listeners "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80" --subnets EnterSubnetsIds --security-group EnterSecurityGroupID

Following are the command and parameters to create Classic Load Balancer:

Command: aws elb create-load-balancer

Parameters:

load-balancer-name: Set load balancer name

listeners: Set listeners for load balancer

Note: In Classic Load Balancer, We are specifying listeners while creating classic load balancer and in case of Application Load Balancer first we created listener separately then register that with load balancer.

Protocol & Port: 

We configured FrontEnd protocol (Protocol=HTTP,LoadBalancerPort=80) that means client request will convert to load balancer via HTTP protocol on port 80.

Also we configured BackEnd protocol (InstanceProtocol=HTTP,InstancePort=80) that means connection between ELB and instances via HTTP protocol on port 80.

subnets: Provide your VPC subnet ids. Specify one subnet per Availability Zone specified

security-group: Provide security group ID

SSLCertificateId: This parameter is only use for HTTPS listener

Output:

{
    "DNSName": "pgLoadBalClassic......elb.amazonaws.com"
}

This DNS address which AWS has been assigned to our new classic load balancer.

You can verify it from aws management console by clicking on "Load Balancer" menu.

Lets see, how to create new listener for existing Classic Load Balancer:

To create new load balancer listener we need to specify name of existing load balancer and specify listener configuration for FrontEnd and BackEnd protocols.

>> aws elb create-load-balancer-listeners --load-balancer-name pgLoadBalClassic --listener "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80"

lets verify it from aws management console by clicking on "Load Balancer" menu.

Happy Learning AWS Services!!!! :) Still Doubts? lets put your questions in below comment box! Thanks!

Watch Video:


Jun 3, 2018

AWS Elastic Load Balancer [ELB] Using CLI Part-1

AWS Elastic Load Balancer [ELB] Using CLI

ELB stands for AWS Elastic Load Balancer. ELB is used to manage load balance between multiple EC2 instances running on AWS cloud. It provides scalability and fault tolerance for application.

What Are The ELB Feature?

  • ELB is fully managed component which manage and distribute incoming application network traffic across multiple EC2 instances which can be in multiple AWS EC2 availability zones.
  • ELB can be used to load balance services in private and public IPs.
  • ELB can be terminate and process incoming secure SSL connection which improve system performance.
  • ELB provides sticky session feature to maintain user Cookie for that particular session and ensure that user session request should sent to same EC2 instance.
  • It provides Auto-Scaling that scale out AWS cloud space automatically.
  • It monitor the health of multiple EC2 instances running behind ELB and configured rules
  • It integrate with Route 53 which enables to configure our application with custom domains and global distribution of application content.

AWS support two types of load balancers:

1. Classic Load Balancer [Old Original Type]
2. Application Load Balancer [Latest Introduced Type]


types-of-load-balancer


1. Classic Load Balancer: is used to route traffic, based on applications or network level details.

It is best option for simple load balancing traffic across multiple EC2 instances where high availability, auto scaling and robust security are basic requirement of application.

It works under 4th layer of OSI model which is Transport Layer.

2. Application Load Balancer: For advanced functionality and application level support we can use Application Load Balancer.

This service operates at Application Layer and allows user to define routing rules based on content across multiple services running on one or more AWS EC2 instances.

It works under layer 7 of OSI model that is Application Layer.


How To Create Application Load Balancer:

We will need subnets and security groups to create Application Load Balancer that we can get from AWS management console which has been assigned to our EC2 instances.

>> aws elbv2 create-load-balancer --name pg-loadbal --subnets EnterMultipleSubnetsIdHere --security-group EnterSecurityGroupID

Once we execute above command, it will create application load balancer that can verify from console by navigating "Load Balancer" menu.

Please save load balancer ARN from output for future reference.


What is Target Group:

It is a groups of all targets within load balancer. Load balancer routes the requests to targets registered with target groups based on load balancers rules.

Targets could be EC2 instances or ECS contains clusters or any other services which can accept request from ELB


How To Create ELB Target Group Using CLI:

To create ELB Target Groups First we need to check status of load balancer that should be in active state.

Go to console click on menu "Load Balancer" and verify state. If state is active then only we can create Target Groups for ELB.

As we have created Application Load Balancer, so we need to use V2 operation commands to create target groups.

>> aws elbv2 create-target-group --name pggroup --protocol HTTP --port 80 --vpc-id EnterVPCIdHere

Application Load Balancer only support HTTP & HTTPS protocol where as Classic Load Balancer support some other protocols like HTTP, HTTPS, TCP, SSL and we need to mention port 80.

Also we need to specify VPC id associate with our ELB which contains same subnets which we provided while creating same ELB.

Once you press enter just save target group ARN for future reference.


How To Create / Register Target In To New Target Group:

>> aws elbv2 register-targets --target-group-arn EnterTargetGroupARNHere --targets Id=EnterTargetId

To register target in target group, we need to provide target group ARN that we just created and targets ID.

Please note Target ID can be EC2 instances id or any other services ids. In this example we are considering EC2 instance id. 

Once you execute command above it will create or register targets in that target group.


What Is The Use Of AWS Listener:

The listener is a process which checks the incoming connection requests on specific protocols and points. This protocol and port combination called as "Front End Connection". We can also define these configuration for back-end instance connections called as "Back-end Connection".

The listeners rules determine how load balancer route the request to the targets in target group.

Classic ELB Listener supports HTTP, HTTPS, TCP and SSL where as Application Load Balancer Listener supports HTTP & HTTPS only.


How To Create Listener & Check Health Of Register Target (In Our Case EC2 Instance) Using AWS CLI:

>> aws elbv2 create-listener --load-balancer-arn EnterLoadBalARNHere --protocol HTTP --port 80 --default-actions Type=forward, TargetGroupArn=EnterTargetGroupARNHere 


To create a listener we can use command "aws elbv2 create-listener" and parameters "load-balancer-arn" which we created earlier can copy from AWS management console then provide protocol and port.

We will use HTTP protocol with port 80 which is most suitable and usual combination for web application.

Then we need to set "default-actions" which means the default action to be taken by load balancer when condition and rules matched.

For example "Type=forward" that means when conditions matched, it forward the request to that defined target group.

Once you execute command you can verify this from console by clicking on Load Balancer menu.

You can see there "Listeners" tab in which you can see newly added listener. Also we can verify health of register target which we just registered.

>> aws elbv2 describe-target-health --target-group-arn EntertargetgrouoARNHere


How To Delete Load Balancer & Target Group:

>> aws elbv2 delete-load-balancer --load-balancer-arn EnterLoadBalARNHere

To delete load balancer we need to provide parameter load "load-balancer-arn" with command "aws elbv2 delete-load-balancers".

To verify go to console click on "Load Balancer" menu.

However if you click on "Target Groups" you will still see Target Group exists.

Lets See How To Delete Target Group Using CLI:

>> aws elbv2 delete-target-group --target-group-arn EnterTargetGroupARNHere

So we need to provide target group ARN to delete that specific target group.

Happy Learning AWS Services!!!! :) Still Doubts? lets put your questions in below comment box! Thanks!

Watch Video: