Automate Birthday Wish On Facebook using Python and AWS

In this post we will share the complete procedure to automatically posting the Birthday wishes on Facebook timeline of our friends. We need to implement below steps to fully automate the process.

  • Python Selenium based script to Login to Facebook to and write Birthday wish.
  • AWS account and Windows server to run the script developed in above step.
  • Schedule the script to run on fix time using Windows task scheduler.
  • Schedule the START and STOP of Windows EC2 server to save the compute cost using AWS Lambda and AWS CloudWatch.


Use the below Python Selenium based script. Below script uses the resources such as chromedrive.exe and pwd.txt file that are put n folder C:\\HappyFB. You can proceed with same folder structure or can change as per your convenience.

Import necessary classes from different modules
 from selenium import webdriver 
 from import By 
 from import WebDriverWait 
 from import expected_conditions as EC 
 from import Options 
 from selenium.common.exceptions import TimeoutException 
 from selenium.webdriver.common.keys import Keys 
 import time 
 chrome_options = webdriver.ChromeOptions()
 path_to_chromedriver = "C:\HappyFB\chromedriver.exe"
 Disbale chrome popup notification.
 prefs = {"profile.default_content_setting_values.notifications": 2} 
 chrome_options.add_experimental_option("prefs", prefs) 
 browser = webdriver.Chrome(path_to_chromedriver, chrome_options=chrome_options) 
 open using get() method
 user_name or e-mail id
 username = ""
 getting passowrd from text file
 with open('C:\HappyFB\pwd.txt', 'r') as myfile: 
     password ='\n', '') 
 print("Let's Begin") 
 Search for EMAIL ID field
 element = browser.find_elements_by_xpath('//*[@id ="email"]') 
 print("Username Entered") 
 Serach for Password Entry Field
 element = browser.find_element_by_xpath('//*[@id ="pass"]') 
 print("Password Entered") 
 logging in
 log_in = browser.find_elements_by_id('loginbutton') 
 print("Login Successfull")
 Traversing to Birthday Notification field
 feed = 'Happy Birthday !'
 element = browser.find_elements_by_xpath("//*[@class ='enter_submit uiTextareaNoResize uiTextareaAutogrow uiStreamInlineTextarea inlineReplyTextArea mentionsTextarea textInput']") 
 cnt = 0
 for el in element: 
     cnt += 1
     element_id = str(el.get_attribute('id')) 
     XPATH = '//*[@id ="' + element_id + '"]'
     post_field = browser.find_element_by_xpath(XPATH) 
     print("Birthday Wish posted for friend" + str(cnt)) 
 Close the browser

The above script is also available on GitHub.


Now create a AWS account and launch the Windows EC2 using the below AMI. This AMI is preinstalled with Pyhton and Selenium. You can also use fresh AMI and then install Pyhton and Selenium.

Refer the below guide to create AWS account if you are new to AWS. Create AWS account.

When launching EC2 search and select the AMI ID: ami-00be6ecf9833e8717 as shown below.

Search for AMI
Searching the AMI


After structuring the script and other required resources as below. Highlighted file are must have requirement.

Directory Structure for Automation Script
Directory Structure

Now open Windows Task Scheduler and schedule the script to run one time a day as per our convenience.

Select the highlighted option task create page.

Windows Task Scheduler Settings
Setting The Task

Select the path of the batch script to set the action for task scheduler.

Setting the action in Windows Task Scheduler.
Setting The Action

Select the time to set the trigger in task scheduler. Please keep in mind that you should set this time 5-10 minutes after the time that you will set in AWS Cloud Watch rules to start the instance.

Setting the trigger in Windows Task Scheduler
Setting The Trigger

Save the above settings and proceed to next step.


We will need to set two AWS Lambda functions-one two start the instance and second to stop the instance and their corresponding AWS Cloud Watch rules to trigger the function once in a day.

Download Python script to STOP and START the instance from GitHub. Enable the Lambda functions in AWS Lambda after downloading.

AWS Lambda
AWS Lambda

Set the rules in AWS CLoudWatch to trigger these lambda functions. Set the time in these rules as per your convenience. The time set here must be 5-10 minutes earlier than the time set in Windows Task Schedule r in STEP-3.

AWS CloudWatch Rules
AWS Cloud Watch Rule

Now your script is ready to execute at the time set by you in Windows task scheduler. EC2 will start automatically at the time set by you in CloudWatch rules.

Please note that Facebook two factor authentication must be disabled in order to execute this script.

If you are new to AWS and want to get your hands dirty on this automation let us know.

Feel free to post your suggestion and improvement.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Share via
Copy link
Powered by Social Snap