In this use case we are going to perform a task where we will configure the Amazon SNS service that will be configured with Amazon EC2 Auto Scaling service. in case any instance is added or terminated then notification will be generated. For notification we are going to use the Email service.
Before going to start the use case lets understand what is AWS SNS service and how it works.
- You can manage the notifications of the resources for your cloud environment using Amazon Simple Notification Service.
- One can get notified when the resources are added or get terminated by the user.
- This is a managed service that provides message delivery from the publishers to the subscribers.
- Application-to-application messaging
- Application-to-person messaging
- Standard and FIFO topics
- Message security and many more
- Create SNS topic from AWS console.
- Subscribe an end point for the SNS topic.
- Create a template to launch ec2 instances.
- Set up an auto scaling group(ASG).
- which will launch and terminate the ec2 instances
- Configure SNS topic with ASG to generate notifications.
Below are the steps which will give you an idea how we can perform the above task.
- Go to the Amazon Console, browse SNS service and go to the SNS dashboard.
- Create an Amazon SNS topic, this SNS topic is a logical access point which is a communication channel point to your service Auto Scaling Group uses to send notifications.
- Subscribe an endpoint to the Amazon SNS topic to receive notification to your Auto Scaling group. In the options, for an endpoint, specify an email address where you want to receive the notifications from Amazon EC2 Auto Scaling.
- Confirm your Amazon SNS subscription, Amazon SNS will send a confirmation mail on the email address you specified. You have to open an email from AWS notification and choose the confirmation link for the subscription.
After successful confirmation, you will receive an acknowledgement message from AWS.
After Subscription is confirmed, your status will show as ‘confirmed’ on a Console.
- In this step we are going to configure the Amazon EC2 Auto Scaling group. Click on the create auto scaling group.
- Before configuring the auto scaling group, we will launch an template for different services. In a launch template box click on the ‘create a launch template’.
- Enter a launch template name and description
- Enter ‘Launch Template Content’ like Amazon Machine Image, Instance type
- Now we have to create a key pair which will be attached to our instances or can select an existing key pair in a ‘key pair login’ option.
- Network Settings:
- Under network setting select ‘Virtual Private Cloud’ as a networking platform.
- For Security group you can select already created security group or default one.
- here we have selected the default security group.
- In storage volume, select ‘Volume 1 (AMI root) (8 GiB, EBS, General purpose SSD (gr2))
- After configuring all the above options we have successfully created the launch template.
- As our template is created we can select that template while creating the auto scaling group which will show all the configuration.
- Auto scaling group configuration settings: choose ‘adhere to launch template’ option in ‘instance purchase options’
- Under network info select default VPC and subnet.
- In a configure advance option, you can choose different options like ‘No load balancer’, ‘Attach to an existing load balancer’, ‘attach to a new load balancer’. Here I am continuing with ‘no load balancer’.
- In step 4 configure group size and scaling policies, select desired capacity, minimum capacity, maximum capacity as 1, 1, 1.
- Under “add notifications” settings select the SNS topic that was created in above step.
- Select an event choose all the four options ‘Launch’, ‘Terminate’, ‘Fail to launch’, ‘Fail to terminate’.
- Then click on next button and add tag for ASG.
- It will a create Auto scaling group.
- After performing all the above steps, we have successfully configured an Amazon SNS with Amazon EC2 auto scaling group and get the notification over the email as I get from the Amazon SNS service for launching an EC2 instance.
Kindly comment here or mail us email@example.com and firstname.lastname@example.org in case of any doubts. We will reach you as soon as possible.