Send Message to Mail, Whatsapp, and Launch AWS Instance Using Face Recognition

Task Description 📄

Create a program that performs the below-mentioned task upon recognizing a particular face.

(1) When it recognizes your face then --
(a) It sends mail to your mail-id by writing this is the face of your_name.
(b)Second, it sends a WhatsApp message to your friend, it can be anything.

(2) When it recognizes the second face, it can be your friend or family member's face.
(a)Create EC2 instance in the AWS using CLI.
(b) Create 5 GB EBS volume and attach it to the instance.


When it recognizes your face then send mail to your mail-id and also send a WhatsApp message to your friend. So let’s start it.

We will need our face dataset so first, we generate the 200 images of our face data through the program.

we will import the library like cv2, numpy, os, pywhatkit, datetime, subprocess, smtplib, etc. we have used a haarcascade classifier to detect the only face. we have captured the image and crop the face and put the particular folder. collected data successfully.

Libraries description

PyWhatKit is a Python library for Sending WhatsApp messages at a certain time. and The subprocess module allows new processes, connect to their input/output/error pipes, and obtain their return codes. The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP listener daemon.

And after that, we will read the image dataset and train the model. and we will also use LBPH Face Recognizer to recognize the face to the dataset.

first, we have installed the “opencv-contrib-python” library

pip install opencv-contrib-python --user

we will create some functions as per the requirement of the task. some functions like - Whatsapp message and mail sending. also, the AWS instance launches and creates EBS volume and attaches to the launched instance using the CLI command.

like this

aws ec2 run-instances --image-id “your image id” --instance-type t2.micro --count 1 --subnet-id “your subnet id” --security-group-ids “security-group-id” --key-name “your key ” -- tag-specifications ResourceType=instance,Tags=[{Key=Name,Value=anyname}] — query Instances[*].[InstanceId] — output text

In this command, we will create the instance and give some commands and subcommands. like - image id, instance type, count, subnet id, security group, key. and pick the launched instance id.

aws ec2 create-volume --volume-type gp2 --availability-zone ap-south-1a --size 5 --tag-specifications=ResourceType=volume,Tags=[{Key=Name, Value= volumename}] --query VolumeId --output text

In this command, we will create the EBS Volume size of 5GB. This also gives the command and subcommand. and pick the created EBS volume id.

aws ec2 attach-volume --volume-id {} --instance-id {} --device /dev/sdf

In this command, attach the EBS volume to the ec2 instance.

We have to create another function to detect the face in a video and draw the circle of the face. also, check the confidence score. and put some text.

GitHub Repo ---To show the program


if the confidence score is above 90 then call the “WhatsApp()” and “email()” function and give the message “hey “ and send the mail to the mail id and also send the WhatsApp message to the friend.


if the confidence score is low and detects another person's face then call the “Instance_EBS() function” and automatically launce the instance and create the EBS volume and attached to the launched instance.

GitHub Repo --



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store